簡體   English   中英

為什么 Tkinter “LabelFrame” 在 Python3 中失敗?

[英]Why is the Tkinter “LabelFrame” failing in Python3?

我試圖弄清楚為什么在為 Python3 調用 Tkinter 中的“LabelFrame”時會收到相同的錯誤消息:

錯誤 output:

回溯(最后一次調用):文件“./example2.py”,第 6 行,在 labelframe_tk=LabelFrame(screen, text="LabelFrame Title") NameError: name 'LabelFrame' is not defined

代碼:

#!/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()

它失敗的原因正是它所說的:你的代碼中沒有定義LabelFrame

鑒於您如何導入 tkinter,您需要使用tkinter.LabelFrame

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM