Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
543 views
in Technique[技术] by (71.8m points)

python - "variable" May be undefined or defined from star imports: 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.

Here is my code:

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()
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

from tkinter import *

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...