【发布时间】:2016-04-29 16:06:08
【问题描述】:
对于线路:
file_Menu.add_command(label = 'New', command = do_Nothing)
为什么函数叫command = do_Nothing而不是command = do_Nothing()?
整个代码如下:
# Tkinter GUI Menu
from tkinter import *
### Functions ###
# Do Nothing
def do_Nothing():
print('I just did... nothing')
### Create tkinter window ###
# Create Window
root = Tk()
#### Creating the Menu(s) ###
# Create the Menu Bar
menu_Bar = Menu(master = root)
# Create File Menu
file_Menu = Menu(master = menu_Bar)
### Displaying the Menu(s) ###
# Display Menu Bar
root.config(menu = menu_Bar)
# Display File Menu
menu_Bar.add_cascade(label = 'File', menu = file_Menu)
### File Menu Properties ####
# New
file_Menu.add_command(label = 'New', command = do_Nothing)
# Open
file_Menu.add_command(label = 'Open', command = do_Nothing)
# Exit
file_Menu.add_command(label = 'Exit', command = root.quit)
### Display tkinter window ###
root.mainloop()
【问题讨论】:
标签: function user-interface python-3.x menu tkinter