我有一個下拉菜單,並希望它不得不選擇註銷。選擇註銷時需要關閉菜單,但我不希望整個程序關閉。退出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