本文整理汇总了Python中tkinter.Menu.add方法的典型用法代码示例。如果您正苦于以下问题:Python Menu.add方法的具体用法?Python Menu.add怎么用?Python Menu.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Menu
的用法示例。
在下文中一共展示了Menu.add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tkinter import Menu [as 别名]
# 或者: from tkinter.Menu import add [as 别名]
def __init__(self, master):
self.dirname = os.path.abspath( os.curdir )
self.initComplete = 0
self.master = master
self.x, self.y, self.w, self.h = -1,-1,-1,-1
# bind master to <Configure> in order to handle any resizing, etc.
# postpone self.master.bind("<Configure>", self.Master_Configure)
self.master.bind('<Enter>', self.bindConfigure)
self.menuBar = Menu(master, relief = "raised", bd=2)
top_Directory = Menu(self.menuBar, tearoff=0)
top_Directory.add("command", label = "Change Dir", command = self.menu_Directory_Change_Dir)
self.menuBar.add("cascade", label="Directory", menu=top_Directory)
#top_Snippet = Menu(self.menuBar, tearoff=0)
self.menuBar.add("command", label = "Run", command = self.menu_Run)
master.config(menu=self.menuBar)
# make a Status Bar
self.statusMessage = StringVar()
self.statusMessage.set(self.dirname)
self.statusbar = Label(self.master, textvariable=self.statusMessage, bd=1, relief=SUNKEN)
self.statusbar.pack(anchor=SW, fill=X, side=BOTTOM)
self.statusbar_bg = self.statusbar.cget('bg') # save bg for restore
myFont = tkinter.font.Font(family="Arial", size=12, weight=tkinter.font.BOLD)
self.statusbar.config( font=myFont )
frame = Frame(master)
frame.pack(anchor=NE, fill=BOTH, side=TOP)
self.Pass_Fail_Button = Button(frame,text="Pass/Fail Will Be Shown Here",
image="", width="15", background="green",
anchor=W, justify=LEFT, padx=2)
self.Pass_Fail_Button.pack(anchor=NE, fill=X, side=TOP)
self.Pass_Fail_Button.bind("<ButtonRelease-1>", self.Pass_Fail_Button_Click)
#self.master.title("tk_nosy")
self.master.title('Python %s.%s.%s '%sys.version_info[:3])
self.oscillator = 1 # animates character on title
self.oscillator_B = 0 # used to return statusbar to statusbar_bg
self.lbframe = Frame( frame )
self.lbframe.pack(anchor=SE, side=LEFT, fill=BOTH, expand=1)
scrollbar = Scrollbar(self.lbframe, orient=VERTICAL)
self.Text_1 = Text(self.lbframe, width="80", height="24", yscrollcommand=scrollbar.set)
scrollbar.config(command=self.Text_1.yview)
scrollbar.pack(side=RIGHT, fill=Y)
self.Text_1.pack(side=LEFT, fill=BOTH, expand=1)
self.master.resizable(1,1) # Linux may not respect this
self.numNosyCalls = 0
self.need_to_pick_dir = 1
if len(sys.argv)>1:
# I don't care what the exception is, if there's a problem, bail
# pylint: disable=W0702
try:
dirname = os.path.abspath( sys.argv[1] )
self.try_change_to_new_dir( dirname )
except:
pass # let Alarm force dir selection
else:
try:
if os.path.isdir(os.path.join( self.dirname, 'tests' )):
self.try_change_to_new_dir( self.dirname )
except:
pass # let Alarm force dir selection
print(LICENSE)
self.Alarm()
示例2: __init__
# 需要导入模块: from tkinter import Menu [as 别名]
# 或者: from tkinter.Menu import add [as 别名]
def __init__(self, master):
self.dirname = os.path.abspath( os.curdir )
self.initComplete = 0
self.master = master
self.x, self.y, self.w, self.h = -1,-1,-1,-1
# bind master to <Configure> in order to handle any resizing, etc.
# postpone self.master.bind("<Configure>", self.Master_Configure)
self.master.bind('<Enter>', self.bindConfigure)
self.menuBar = Menu(master, relief = "raised", bd=2)
self.menuBar.add("command", label = "Change_Dir", command = self.menu_Directory_Change_Dir)
disp_Choices = Menu(self.menuBar, tearoff=0)
self.display_test_details = StringVar()
self.display_test_details.set('N')
disp_Choices.add_checkbutton(label='Display Test Details', variable=self.display_test_details, onvalue='Y', offvalue='N')
self.display_watched_files = StringVar()
self.display_watched_files.set('N')
disp_Choices.add_checkbutton(label='Show Watched Files', variable=self.display_watched_files, onvalue='Y', offvalue='N')
self.menuBar.add("cascade", label="Display", menu=disp_Choices)
py_choices = Menu(self.menuBar, tearoff=0)
py_choices.add("command", label = "Change Python Version",
command = self.changePythonVersion)
py_choices.add("command", label = "Find New Python Interpreter",
command = self.findNewPythonInterpreter)
py_choices.add("command", label = "Launch Another Python Interpreter",
command = self.launchAnotherPythonInterpreter)
self.menuBar.add("cascade", label="Python", menu=py_choices)
#top_Snippet = Menu(self.menuBar, tearoff=0)
self.menuBar.add("command", label = "Run", command = self.menu_Run)
self.display_test_details.trace("w", self.rerun_tests)
self.display_watched_files.trace("w", self.rerun_tests)
master.config(menu=self.menuBar)
# make a Status Bar
self.statusMessage = StringVar()
self.statusMessage.set(self.dirname)
self.statusbar = Label(self.master, textvariable=self.statusMessage,
bd=1, relief=SUNKEN)
self.statusbar.pack(anchor=SW, fill=X, side=BOTTOM)
self.statusbar_bg = self.statusbar.cget('bg') # save bg for restore
self.arial_12_bold_font = tkinter.font.Font(family="Arial", size=12,
weight=tkinter.font.BOLD)
self.arial_12_font = tkinter.font.Font(family="Arial", size=12)
self.statusbar.config( font=self.arial_12_bold_font )
frame = Frame(master)
frame.pack(anchor=NE, fill=BOTH, side=TOP)
self.Pass_Fail_Button = Button(frame,text="Pass/Fail Will Be Shown Here",
image="", width="15", background="green",
anchor=W, justify=LEFT, padx=2)
self.Pass_Fail_Button.pack(anchor=NE, fill=X, side=TOP)
self.Pass_Fail_Button.bind("<ButtonRelease-1>", self.Pass_Fail_Button_Click)
self.master.title("tk_nosy")
self.oscillator = 1 # animates character on title
self.oscillator_B = 0 # used to return statusbar to statusbar_bg
self.lbframe = Frame( frame )
self.lbframe.pack(anchor=SE, side=LEFT, fill=BOTH, expand=1)
scrollbar = Scrollbar(self.lbframe, orient=VERTICAL)
self.Text_1 = Text(self.lbframe, width="80", height="24",
yscrollcommand=scrollbar.set)
scrollbar.config(command=self.Text_1.yview)
scrollbar.pack(side=RIGHT, fill=Y)
self.Text_1.pack(side=LEFT, fill=BOTH, expand=1)
self.master.resizable(1,1) # Linux may not respect this
self.numNosyCalls = 0
self.need_to_pick_dir = 1
print('sys.argv =',sys.argv)
if len(sys.argv)>1:
# I don't care what the exception is, if there's a problem, bail
# pylint: disable=W0702
print( "Try Dir =",sys.argv[1] )
try:
dirname = os.path.abspath( sys.argv[1] )
self.try_change_to_new_dir( dirname )
except Exception:
pass # let Alarm force dir selection
#.........这里部分代码省略.........
示例3: _Tk_Nosy
# 需要导入模块: from tkinter import Menu [as 别名]
# 或者: from tkinter.Menu import add [as 别名]
class _Tk_Nosy(object):
"""This class is the tkinter GUI object"""
def __init__(self, master):
self.dirname = os.path.abspath( os.curdir )
self.initComplete = 0
self.master = master
self.x, self.y, self.w, self.h = -1,-1,-1,-1
# bind master to <Configure> in order to handle any resizing, etc.
# postpone self.master.bind("<Configure>", self.Master_Configure)
self.master.bind('<Enter>', self.bindConfigure)
self.menuBar = Menu(master, relief = "raised", bd=2)
top_Directory = Menu(self.menuBar, tearoff=0)
top_Directory.add("command", label = "Change Dir", command = self.menu_Directory_Change_Dir)
self.menuBar.add("cascade", label="Directory", menu=top_Directory)
#top_Snippet = Menu(self.menuBar, tearoff=0)
self.menuBar.add("command", label = "Run", command = self.menu_Run)
master.config(menu=self.menuBar)
# make a Status Bar
self.statusMessage = StringVar()
self.statusMessage.set(self.dirname)
self.statusbar = Label(self.master, textvariable=self.statusMessage, bd=1, relief=SUNKEN)
self.statusbar.pack(anchor=SW, fill=X, side=BOTTOM)
self.statusbar_bg = self.statusbar.cget('bg') # save bg for restore
myFont = tkinter.font.Font(family="Arial", size=12, weight=tkinter.font.BOLD)
self.statusbar.config( font=myFont )
frame = Frame(master)
frame.pack(anchor=NE, fill=BOTH, side=TOP)
self.Pass_Fail_Button = Button(frame,text="Pass/Fail Will Be Shown Here",
image="", width="15", background="green",
anchor=W, justify=LEFT, padx=2)
self.Pass_Fail_Button.pack(anchor=NE, fill=X, side=TOP)
self.Pass_Fail_Button.bind("<ButtonRelease-1>", self.Pass_Fail_Button_Click)
#self.master.title("tk_nosy")
self.master.title('Python %s.%s.%s '%sys.version_info[:3])
self.oscillator = 1 # animates character on title
self.oscillator_B = 0 # used to return statusbar to statusbar_bg
self.lbframe = Frame( frame )
self.lbframe.pack(anchor=SE, side=LEFT, fill=BOTH, expand=1)
scrollbar = Scrollbar(self.lbframe, orient=VERTICAL)
self.Text_1 = Text(self.lbframe, width="80", height="24", yscrollcommand=scrollbar.set)
scrollbar.config(command=self.Text_1.yview)
scrollbar.pack(side=RIGHT, fill=Y)
self.Text_1.pack(side=LEFT, fill=BOTH, expand=1)
self.master.resizable(1,1) # Linux may not respect this
self.numNosyCalls = 0
self.need_to_pick_dir = 1
if len(sys.argv)>1:
# I don't care what the exception is, if there's a problem, bail
# pylint: disable=W0702
try:
dirname = os.path.abspath( sys.argv[1] )
self.try_change_to_new_dir( dirname )
except:
pass # let Alarm force dir selection
else:
try:
if os.path.isdir(os.path.join( self.dirname, 'tests' )):
self.try_change_to_new_dir( self.dirname )
except:
pass # let Alarm force dir selection
print(LICENSE)
self.Alarm()
def try_change_to_new_dir(self, dirname):
"""A legal abspath will switch to dirname."""
# I don't care what the exception is, if there's a problem, bail
# pylint: disable=W0702
if dirname:
try:
dirname = os.path.abspath( dirname )
except:
return # let Alarm force dir selection
else:
return
self.dirname = dirname
#.........这里部分代码省略.........
示例4: Tk_Nosy
# 需要导入模块: from tkinter import Menu [as 别名]
# 或者: from tkinter.Menu import add [as 别名]
class Tk_Nosy(object):
"""This class is the tkinter GUI object"""
# make a collection of python interpreters to choose from
pythonInterpreterCollection = None # will be PyInterpsOnSys object
# extra python interpreters can run nosetests concurrently to main window
# concurrent_versionL contains tuples = (PI, Popup)
concurrent_versionL = [] # additional running python interpreters
def __init__(self, master):
self.dirname = os.path.abspath( os.curdir )
self.initComplete = 0
self.master = master
self.x, self.y, self.w, self.h = -1,-1,-1,-1
# bind master to <Configure> in order to handle any resizing, etc.
# postpone self.master.bind("<Configure>", self.Master_Configure)
self.master.bind('<Enter>', self.bindConfigure)
self.menuBar = Menu(master, relief = "raised", bd=2)
self.menuBar.add("command", label = "Change_Dir", command = self.menu_Directory_Change_Dir)
disp_Choices = Menu(self.menuBar, tearoff=0)
self.display_test_details = StringVar()
self.display_test_details.set('N')
disp_Choices.add_checkbutton(label='Display Test Details', variable=self.display_test_details, onvalue='Y', offvalue='N')
self.display_watched_files = StringVar()
self.display_watched_files.set('N')
disp_Choices.add_checkbutton(label='Show Watched Files', variable=self.display_watched_files, onvalue='Y', offvalue='N')
self.menuBar.add("cascade", label="Display", menu=disp_Choices)
py_choices = Menu(self.menuBar, tearoff=0)
py_choices.add("command", label = "Change Python Version",
command = self.changePythonVersion)
py_choices.add("command", label = "Find New Python Interpreter",
command = self.findNewPythonInterpreter)
py_choices.add("command", label = "Launch Another Python Interpreter",
command = self.launchAnotherPythonInterpreter)
self.menuBar.add("cascade", label="Python", menu=py_choices)
#top_Snippet = Menu(self.menuBar, tearoff=0)
self.menuBar.add("command", label = "Run", command = self.menu_Run)
self.display_test_details.trace("w", self.rerun_tests)
self.display_watched_files.trace("w", self.rerun_tests)
master.config(menu=self.menuBar)
# make a Status Bar
self.statusMessage = StringVar()
self.statusMessage.set(self.dirname)
self.statusbar = Label(self.master, textvariable=self.statusMessage,
bd=1, relief=SUNKEN)
self.statusbar.pack(anchor=SW, fill=X, side=BOTTOM)
self.statusbar_bg = self.statusbar.cget('bg') # save bg for restore
self.arial_12_bold_font = tkinter.font.Font(family="Arial", size=12,
weight=tkinter.font.BOLD)
self.arial_12_font = tkinter.font.Font(family="Arial", size=12)
self.statusbar.config( font=self.arial_12_bold_font )
frame = Frame(master)
frame.pack(anchor=NE, fill=BOTH, side=TOP)
self.Pass_Fail_Button = Button(frame,text="Pass/Fail Will Be Shown Here",
image="", width="15", background="green",
anchor=W, justify=LEFT, padx=2)
self.Pass_Fail_Button.pack(anchor=NE, fill=X, side=TOP)
self.Pass_Fail_Button.bind("<ButtonRelease-1>", self.Pass_Fail_Button_Click)
self.master.title("tk_nosy")
self.oscillator = 1 # animates character on title
self.oscillator_B = 0 # used to return statusbar to statusbar_bg
self.lbframe = Frame( frame )
self.lbframe.pack(anchor=SE, side=LEFT, fill=BOTH, expand=1)
scrollbar = Scrollbar(self.lbframe, orient=VERTICAL)
self.Text_1 = Text(self.lbframe, width="80", height="24",
yscrollcommand=scrollbar.set)
scrollbar.config(command=self.Text_1.yview)
scrollbar.pack(side=RIGHT, fill=Y)
self.Text_1.pack(side=LEFT, fill=BOTH, expand=1)
self.master.resizable(1,1) # Linux may not respect this
self.numNosyCalls = 0
self.need_to_pick_dir = 1
#.........这里部分代码省略.........