我有一个下拉菜单,并希望它不得不选择注销。选择注销时需要关闭菜单,但我不希望整个程序关闭。退出Tkinter下拉菜单
我尝试过像root.quit()这样的方法,但它说root并没有被定义,即使它是。什么是关闭菜单的最佳方式。在菜单的代码是:
from tkinter import *
def edit_or_retrieve():
root = Tk()
root.title("Main Menu")
menu = Frame(root)
menu.pack(pady = 5, padx = 50)
var = StringVar(root)
options = [
'Enter',
'Edit',
'Retrieve',
'Report 1 - Dates of birth',
'Report 2 - Home phone numbers',
'Report 3 - Home addresses',
'Log off',
]
option = OptionMenu(menu, var, options[0], *options, command=function)
var.set('Select')
option.grid(row = 1, column = 1)
root.mainloop()
def function(value):
if value == 'Edit':
edit()
if value == 'Enter':
enter()
if value == 'Retrieve':
display()
if value == 'Report 1 - Dates of birth':
reportone()
if value == 'Report 2 - Home phone numbers':
reporttwo()
if value == 'Report 3 - Home addresses':
reportthree()
if value == 'Log off':
#this is where the command or function name needs to go,
#however I am not sure what it should be.
根变量函数[范围](http://python-textbok.readthedocs.io/en/1.0/Variables_and_Scope.html)只 – SmartManoj