我正在使用Tkinter / Python,我编写了以下代码:
from Tkinter import *
from ScrolledText import *
#dummy function to be changed later
def dummy():
print 'Oont ooncha, oont ki peeth oonchi, neechi oonth ki poonch!'
#create your main window
root = Tk(className = 'Mere Bhains wala Editor')
#mera menu
my_menu = Menu(root)
#attach this menu to the the application
root.config(menu = my_menu)
#create my file menu
filemenu = Menu(my_menu)
filemenu.add_command(label = 'New', command = dummy)
filemenu.add_command(label = 'Open', command = dummy)
filemenu.add_separator()
filemenu.add_command(label = 'Save', command = dummy)
filemenu.add_command(label = 'Save as', command = dummy)
my_menu.add_cascade(label = 'File', menu = filemenu)
#create Help menu
helpmenu = Menu(my_menu)
helpmenu.add_command(label = 'Terms of use', command = dummy)
helpmenu.add_command(label = 'Documents', command = dummy)
helpmenu.add_command(label = 'FAQ', command = dummy)
helpmenu.add_separator()
helpmenu.add_command(label = 'Community discussions', command = dummy)
helpmenu.add_command(label = 'Report issue', command = dummy)
helpmenu.add_command(label = 'Search issues', command = dummy)
my_menu.add_cascade(label = 'Help', menu = helpmenu)
#create the scrolled text area
textpad = ScrolledText(root, width=640, height = 480)
textpad.pack()
# run the window as the application
root.mainloop()
如果我运行此代码,那么我会得到两个标题为“文件和帮助”的级联菜单。现在问题,
我希望“帮助”菜单右对齐,“文件”菜单左对齐。还有什么额外的代码,以便我可以实现这一目标?
答案 0 :(得分:2)
您使用现有Tkinter库执行的任何操作都将是一次攻击。它只是不支持右对齐菜单条目。但是这里有一些可以做的黑客攻击:
答案 1 :(得分:2)
你无法控制这一点。 official tk documentation非常全面,列出了所有可能的内容,并没有列出与对齐相关的任何内容。