Python Tkinter menu bars don't display

后端 未结 4 1755
孤街浪徒
孤街浪徒 2021-01-06 05:12

I\'m trying to make a GUI using Tkinter and have come to implementing a menu bar. I\'ve looked at a few tutorials and written some code for it, but a menu bar never seems to

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-06 05:40

    I am trying the code as above, but all I get is "Python" on the macOS menubar and it's usual pulldown. tkinter just doesn't seem to work menus on macOS 10.14.1

    I think what is happening is that there are mac specific fixups that are changing the event codes so certain menu items will end up under the Python menu item instead of where expected, I saw some of this in my own experiments. When I expanded my code and used some of the reserved FILE event codes instead of the standard ones, things worked better.

    #!/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7
    # -*- coding: utf-8 -*-# -*- coding: utf-8 -*-
    
    from tkinter import *
    
    class App(Frame):
        def __init__(self, master):
            Frame.__init__(self, master)
            self.grid()
            self.widgets()
    
        def widgets(self):
            menubar = Menu(root)
            menubar.add_command(label = 'File')
            menubar.add_command(label = 'quit', command = root.quit())
            root.config(menu = menubar)
    
    root = Tk()
    root.title('Menubar')
    app = App(root)
    root.mainloop()
    

提交回复
热议问题