简体   繁体   中英

Why is the Tkinter “LabelFrame” failing in Python3?

I'm trying to figure out why I get the same error message when invoking the "LabelFrame" in Tkinter for Python3:

Error output:

Traceback (most recent call last): File "./example2.py", line 6, in labelframe_tk=LabelFrame(screen, text="LabelFrame Title") NameError: name 'LabelFrame' is not defined

Code:

#!/usr/bin/python3
import tkinter
screen=tkinter.Tk()
screen.geometry('300x300')

labelframe_tk=LabelFrame(screen, text="LabelFrame Title")
labelframe_tk.pack(fill="both", expand="yes")

inside=Label(labelframe_tk, text="Whatever goes here!")
inside.pack()

screen.mainloop()

It's failing for exactly the reason it says: there is nothing in your code that defines LabelFrame .

Given how you've imported tkinter, you need to use tkinter.LabelFrame .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM