TeemoMain TeemoMain - 1 year ago 144
Python Question

"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()

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download