Is There Any Differences Between Python2 And Python3 About Adding Menu Bar To Frame In Tkinter?
I'm trying to porting a project 2to3 on python, and stuck in tkinter. In python2, there is no problem with adding menu bar to Frame in tkinter, but python3 occured attribute error.
Solution 1:
You should not be using tk_menuBar
in either python 2 or 3. The docstring for that function says this:
"""Do not use. Needed in Tk 3.6 and earlier."""
Note: tk 3.6 went obsolete back in the early 90's.
There is no way to attach a menu to a Frame
widget. You can add instances of Menubutton
to simulate a menubar, but you won't get a real menubar.
You can attach a Menu
to the root window or to instances of Toplevel
by configuring the menu
attribute.
import tkinter as tk
root = tk.Tk()
menubar = tk.Menu()
fileMenu = tk.Menu()
editMenu = tk.Menu()
viewMenu = tk.Menu()
menubar.add_cascade(label="File", menu=fileMenu)
menubar.add_cascade(label="Edit", menu=editMenu)
menubar.add_cascade(label="View", menu=viewMenu)
root.configure(menu=menubar)
root.mainloop()
Post a Comment for "Is There Any Differences Between Python2 And Python3 About Adding Menu Bar To Frame In Tkinter?"