www.un.org/Depts/DGACM/index_spanish.htm • 如何以Tkinter
我正试图利用Tkinter实施一个全球倡议方案,该方案需要从菜巴获得许多职能。 但我必须找到一种办法,把这些职能有效地包给每个菜单。
- how do i approach to create a menubar using object oriented approach with each menu having a lot of functions? Is a seperate class for menubar good idea? if yes, how do i implement it
import tkinter as tk
class MainWindow(tk.Tk):
def __init__(self):
super().__init__()
self.geometry( 900x600 )
self.resizable(0, 0)
self.InitContents()
def InitContents(self):
container = tk.Frame(self)
container.pack(fill=tk.BOTH,expand=True)
root_menu=tk.Menu(self)
self.config(menu=root_menu)
fileMenu = tk.Menu(root_menu)
editMenu = tk.Menu(root_menu)
viewMenu = tk.Menu(root_menu)
settingMenu = tk.Menu(root_menu)
root_menu.add_cascade(label= File ,menu=fileMenu)
root_menu.add_cascade(label= Edit ,menu=editMenu)
root_menu.add_cascade(label= View ,menu=viewMenu)
root_menu.add_cascade(label= Settings ,menu=settingMenu)
#
#i need to add a lot of functions to respective Menus
if __name__ == "__main__":
root = MainWindow()
root.mainloop()
how do i put my category for menubar
class SomeClass:
def __init__(self):
#does something
pass
def open_file():
pass
def save_file():
pass
def redo():
pass
def exit():
pass
#etc.....