本文介绍了“变量"可能未定义或从星导入定义:tkinter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..我正在尝试为 gui 制作一个简单的轮廓,但我收到了警告"variable" 可能未定义或从 star 导入定义:tkinter 用于我的所有变量.
I'm trying to make a simple outline for a gui, and I'm getting the warning "variable" May be undefined or defined from star imports: tkinter for all of my variables.
这是我的代码:
from tkinter import *
class myApp :
def __init__(self, gui,) :
self.root = gui
self.bframe = Frame(self.root) # Create a container Frame at bottom
self.bframe.pack(side=BOTTOM)
self.xlabel = Label(self.root, text="Item ID") # Create the Label
self.xlabel.pack(side=LEFT)
self.xentry = Entry(self.root, bd=5) # Create the Entry box
self.xentry.pack(side=LEFT)
self.xentry.bind('<Return>', self.showStockItem)
self.xentry.focus_set() # Set focus in the Entry box
self.xopen = Button(self.root, text="Show", command=self.showStockItem) # Create the open Button
self.xopen.pack(side=LEFT)
self.xquit = Button(self.bframe, text="Quit", command=self.quitit) # Create the quit Button
self.xquit.pack(side=BOTTOM)
return
gui = Tk()
gui.title("Travel")
app = myApp(gui)
gui.mainloop()
推荐答案
from tkinter import *
在这一行中,您从 tkinter
导入所有内容.不建议这样做,因此 linter 会警告您.但如果你真的想这样做,也没关系,直接无视就好.
In this line, you import everything from tkinter
. This is not recommended, so linter will warn you. But if you really want to do this, it's OK, just ignore it.
为了更好,您应该明确导入您需要的内容.例如:
To be better, you should explicitly import what you need. For example:
from tkinter import Tk, Label, Frame, Entry, Button
这篇关于“变量"可能未定义或从星导入定义:tkinter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论