UnboundLocalError:分配前已引用局部变量“ FrameTable”

时间:2019-05-18 08:24:31

标签: python tkinter frames

我想隐藏Tkinter中单击按钮上的帧。问题是表是 隐藏并覆盖上一帧

---------搜索框---

if(C1.get()=="Emp_ID"):
    tableframe=Frame(SearchFrame,bg="#4c5d34")
    style = ttk.Style().configure("Treeview.Heading",background="#2b411c",foreground="black",relief=GROOVE,font=('Palatino linotype',10,"bold"))
    treeview=ttk.Treeview(tableframe,column=("ID","Name","Department","Status","Duty Time","Rank","In Time","Out Time"),show='headings',height=18)
    treeview.column("ID",width=150)
    treeview.column("Name",width=150)
    treeview.column("Department",width=150)
    treeview.column("Status",width=150)
    treeview.column("Duty Time",width=150)
    treeview.column("Rank",width=150)
    treeview.column("In Time",width=150)
    treeview.column("Out Time",width=150)
    treeview.heading("#1",text="ID")
    treeview.heading("#2",text="Name")
    treeview.heading("#3",text="Department")
    treeview.heading("#4",text="Status")
    treeview.heading("#5",text="Duty Time")
    treeview.heading("#6",text="Rank")
    treeview.heading("#7",text="In Time")
    treeview.heading("#8",text="Out Time")
    #treeview.bind("<Double-1>",onDoubalclick)
    treeview.pack(pady=30)
    tableframe.pack()
    FrameTable.pack_forget()


elif(C1.get()=="Transport"):
    FrameTable=Frame(SearchFrame,bg="#4c5d34")
    style = ttk.Style().configure("Treeview.Heading",background="#2b411c",foreground="black",relief=GROOVE,font=('Palatino linotype',10,"bold"))
    treeview=ttk.Treeview(FrameTable,column=("Vichle Type","Vichle No","Driver ID","Status","In Time","Out Time","Date","Source","Destination"),show='headings',height=18)
    treeview.column("Vichle Type",width=150)
    treeview.column("Vichle No",width=150)
    treeview.column("Driver ID",width=150)
    treeview.column("Status",width=150)
    treeview.column("In Time",width=150)
    treeview.column("Out Time",width=150)
    treeview.column("Date",width=150)
    treeview.column("Source",width=150)
    treeview.column("Destination",width=150)

    treeview.heading("#1",text="Vichle Type")
    treeview.heading("#2",text="Vichle No")
    treeview.heading("#3",text="Driver ID")
    treeview.heading("#4",text="Status")
    treeview.heading("#5",text="In Time")
    treeview.heading("#6",text="Out Time")
    treeview.heading("#7",text="Date")
    treeview.heading("#8",text="Source")
    treeview.heading("#9",text="Destination")
    #treeview.bind("<Double-1>",onDoubalclick)
    treeview.pack(pady=30)
    FrameTable.pack()

错误是:

  

UnboundLocalError:分配前已引用局部变量'FrameTable'

1 个答案:

答案 0 :(得分:0)

tableframe=Frame(SearchFrame,bg="#4c5d34")

我相信您打算将变量称为FrameTable

否则,由于尚未将变量分配给FrameTable.pack_forget(),因此调用将失败。