typeSel.get()不起作用

时间:2014-05-14 06:32:55

标签: python tkinter

from Tkinter import *

def add_item():

    def create_rec(item):

        def saveREC():

            print typeSel.get()

        label2=Label(add_win, text="select item type:").pack()

        #radio buttons creation
        typeSel = StringVar()
        R1 = Radiobutton(add_win, text="meat", variable=typeSel, value="meat")                  
        R1.pack( anchor = W)

        saveBttn=Button(add_win, text="recognize this item in the future", command=saveREC).pack()

    def saveEntry():
        item=entry.get()
        a,typeVar=fridgePK.item_recognition(item)
        if a==True:
            print item, " is saved to ", typeVar

        #if item isn't recognized then user can add item to recognition list        
        if a==False:
            create_rec(item)

    add_win=Tk()

    entry=Entry(add_win, width=30)
    entry.pack()
    entry.focus_set()

    saveBttn=Button(add_win, text="add item", width=25, command=saveEntry)
    saveBttn.pack()

    add_win.mainloop()

我正在尝试将项目保存到与所选名为typeSel的无线电值对应的文件中。我尝试通过typeSel.get()调用无线电值但没有发生任何事情。这是为什么?当我自己拉出功能时它工作正常但不在这里。

0 个答案:

没有答案