tkinter选项菜单不显示选择
我有一个用Python和tkinter写的程序,里面用到了选项菜单,运行得很好。不过在第二个窗口(这个窗口是从主窗口打开的,算是一个独立的tk执行)中,选的选项在选项菜单里不显示。我测试过,选项确实被选中了,我也能使用它,只是它不显示出来。
下面这个类是由主窗口调用的:
class ftp_window:
def __init__(self):
root = Tk()
root.resizable(width=FALSE, height=FALSE)
root.title("Unity Acesso ao FTP")
root.iconbitmap("icon.ico")
note = Notebook(root)
self.tab1 = Frame(note)
self.tab2 = Frame(note)
note.add(self.tab1, text = "Acessar Bases")
note.add(self.tab2, text = "ANALISE")
root.minsize(600,500)
root.geometry("600x500")
self.ftp_apelido = StringVar()
self.ftp_apelido.set("Select")
self.varvoz = StringVar()
self.tab_one()
note.pack()
root.mainloop()
def get_list_of_apelidos(self):
'''sqlite3 connection for ftp connections'''
conn = sqlite3.connect("settings.db")
c = conn.cursor()
c.execute("select * from ftp_server_login")
results = c.fetchall()
list = ()
for line in results:
if not re.search(line[4], str(list)):
list += (line[4],)
else:
pass
return list
def prints(self, *args):
'''used to display the stringvar when selected.'''
print args
print self.ftp_apelido.get()
def tab_one(self):
'''creates the first tab and it's widgets'''
main_tab_one_frame = Frame(self.tab1)
main_tab_one_frame.config(width=300)
main_tab_one_frame.grid(column=0, row=0, sticky=NSEW, rowspan=10, columnspan=10)
apelidos_Entry = OptionMenu(main_tab_one_frame, self.ftp_apelido, self.ftp_apelido.get(), *self.get_list_of_apelidos())
apelidos_Entry.config(width=25)
apelidos_Entry.grid(column=3, row=3)
vozEntry=OptionMenu(main_tab_one_frame, self.varvoz, '', '', 'SIM', 'NAO')
vozEntry.config(width=15)
vozEntry.grid(column=1, row=4)
1 个回答
2
如果你创建了多个 Tk
的实例,那这至少是问题的一部分。你应该只为你的整个应用程序创建一个 Tk
的实例,并且只应该调用一次 mainloop
。如果你需要更多的窗口,应该创建 Toplevel
的实例。