Despite all attempts, I cannot seem to get Entry().get() to assign a string in an Entry window. Here's a code snippet:
Itx_bcn_ent = Entry(win).grid(row=1,column=1)
I define a button to call a function:
btn = Button(win,text="Run",command=getnums).grid(row=5,column=3,padx=100)
Here's the function:
def getnums():
Itx_bcn = Itx_bcn_ent.get()
When I run the script, I get the following error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1482, in __call__
return self.func(*args)
File "C:\Python34\voltage_substate_GUI.py", line 7, in getnums
Itx_bcn = Itx_bcn_ent.get()
AttributeError: 'NoneType' object has no attribute 'get'
I've seen the construct to use a Class StringVar() and the option "textvariable=" with the Entry() object, however doing this seems overly complicated as it just creates an additional set of variables between what's in the Entry window and the variable I am trying to assign.
Any thoughts on this?
Entry.grid() returns None, so when you do something = Entry(root).grid(), you're getting something=None.
This isn't a problem until you try to use that thing! That's why you're getting a 'NoneType' object has no attribute 'get' error.
Itx_bcn_ent = Entry(win)
Itx_bcn_ent.grid(row=1,column=1)
Now your button works :), though you have the same problem with your btn = line. I've yet to have to reuse that assignment, so maybe just drop it?
Button(win,text="Run",command=getnums).grid(row=5,column=3,padx=100)
Related
I'm trying to make a GUI for my app, but I have hit a roadblock when trying to make a settings Toplevel. This Toplevel comes with tabs and setting buttons that start at the same state their respective settings are stored as from last settings/defaults.
Here is the exception I am currently getting:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\tkinter\__init__.py", line 1885, in __call__
return self.func(*args)
File "KMIU 4\kmiu_dv7.pyw", line 38, in settings
sett.display(main)
File "KMIU 4\bk\settings.py", line 54, in __init__
self.windowsettings(tab2)
File "KMIU 4\bk\settings.py", line 23, in windowsettings
if settings['Fullscreen'].get(): fs_butt.select()
AttributeError: 'Checkbutton' object has no attribute 'select'
Here is the bit of code that is causing the issue:
def windowsettings(self, tab):
global settings
text = Label(tab, text ="sample text")
text.grid(columnspan = 2)
fs_butt = Checkbutton(
tab,
text="Fullscreen",
command=lambda: settings['Fullscreen'].set(not settings['Fullscreen'].get()))
print(settings)
fs_butt.grid(row=1)
if settings['Fullscreen'].get(): fs_butt.select()
For me in my code with tk.Checkbutton, select() works, and ive seen some other people having the same issue, not sure whats causing it(maybe your using ttk.Checkbutton), but here is a way around:
First assign a BooleanVar() to your checkbutton:
var = BooleanVar()
....
fs_butt = Checkbutton(tab,variable=var,......) #same for ttk.Checkbutton(..) too
Now to set the value of the variable to True, to select, and False to deselect:
if settings['Fullscreen'].get():
var.set(True)
Or maybe your using ttk.Checkbutton which does not have select() and deselect()
I am beginning to get the hang of tkinter, but I have run into a problem. I want to create a label that displays an appropriate message according to the values of an Entry field, checked by a button. When this is used repeatedly, using just the tk.Label command will just overlay on top of the existing label, So I am trying to assign the label to a variable:
messagebox=tk.Label(root2,text=" ",font(style,font).grid(row=1,column=0,columnspan = 50))
I want to later on use the .configure command to change this text, However I get this error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:[CENSORED BY POSTER (me), It was just the file directory]", line 84, in Checkpass
messagebox = tk.Label(root2,text=" ",font=(style,font).grid(row=1,column=0,columnspan = 50))
AttributeError: 'tuple' object has no attribute 'grid'
Can anyone please tell me what I am doing wrong and explain why it wont work.
Thank you,
Tava
Check your parentheses at font(style,font).grid. Probably should be:
messagebox=tk.Label(root2,text=" ",font(style,font)).grid(row=1,column=0,columnspan = 50)
But I personally recommend split it into two lines for the sake of readability:
messagebox = tk.Label(root2, text=" ", font(style, font))
messagebox.grid(row=1, column=0, columnspan = 50)
I have made a tkinter program where i keep getting this error:
File "F:\Programming 2\Gui\Gui #11.py", line 78, in shape_workit
cylinder(pos=(0,0,0),axis=(1,0,0),color=self.color3.get(),
AttributeError: 'Kinter' object has no attribute 'color3'
Here is the code which the error occurs from:
def shapescolor(self):
if self.color1.get()=="Does a Orange":
color3=color.orange
if self.color1.get()=="Does a Blue":
color3=color.blue
def shape_workit(self):
try:
if self.shape.get()=="Does a Cylinder": #Creates Cylinder
cylinder(pos=(0,0,0),axis=(1,0,0),color=self.color3.get() ##ERROR HERE,
radius=float(self.radius.get()))
Here is the Code where the error it gets from
My guess is that you need to be doing self.color3 = ... rather than color3 = ..., since you're later refering to self.color3 and haven't set that attribute anywhere else in the code you posted.
I've recently started learning Python and started using it to create label expressions in ArcMap. I ran into an error today that I can't figure out though (and seems like it should be simple). When I try to create the following expression:
def FindLabel ( [FacilityName] ):
S = [FacilityName]
S = S.upper()
return S
I get back an error as follows:
Error 0 on line 0.
Error running expression: FindLabel(ESRIExpressionArg0)
Traceback (most recent call last):
File "<expression>", line 1, in <module>
File "<string>", line 3, in FindLabel
AttributeError: 'NoneType' object has no attribute 'upper'.
[FacilityName] is a domained field, and Null values are allowed. I understand, I think, that 'NoneType' means that [FacilityName] is being given a None value before it's trying to be returned, but I don't know how to fix the problem.
Thanks,
Ethan
I'm pretty sure all the values get returned as strings, but in the case of a null value, it might be returned as None, which would explain the error you're getting.
You can use a try..except block or make a conditional statement inside your function to ignore None values.
Here's with try..except:
def FindLabel ( [FacilityName] ):
try:
S = [FacilityName]
S = S.upper()
return S
except AttributeError:
pass
I'm running some python code and get an error:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1413, in __call__
return self.func(*args)
File "multiline14.py", line 28, in getText
if encodinghex in process:
TypeError: argument of type 'function' is not iterable
My def is below.
def gui(item):
def default_encode(s):
pass
# map items from menu to commands
encodinghex = '.encode("hex")'
decodinghex = '.decode("hex")'
mapping = {"encode_b64": base64.encodestring,"encode_url": urllib.quote_plus,"encode_hex": encodinghex, "decode_b64": base64.decodestring, "decode_url": urllib.unquote_plus, "decode_hex": decodinghex}
process = mapping.get(item, default_encode)
def getText():
#clear bottom text field
bottomtext.delete(1.0, END)
#var equals whats in middle
var = middletext.get(1.0, 'end-1c')
#insert encoded var in bottom
if encodinghex in process:
var = '"%s"' % (var)
bottomtext.insert(INSERT, eval(var + process))
elif decodinghex in process:
var = '"%s"' % (var)
bottomtext.insert(INSERT, eval(var + process))
else:
bottomtext.insert(INSERT, process(var))
What causes that error?
You are requesting a function from mapping here:
process = mapping.get(item, default_encode)
You then try and iterate it here:
if encodinghex in process:
You can't use the in keyword unless the subject is Iterable.
What you're trying to achieve here is to actually see which function your call to mapping.get() returned
if process == encodinghex:
Note that base64.encodestring, urllib.quote_plus, encodinghex, base64.decodestring, urllib.unquote_plus, decodinghex are all functions
What you've done doesn't seem to make any sense at all. You have two text strings, encodinghex and decodinghex, which you're using eval to turn into code to execute. But in your mapping dict alongside those you've also got various actual methods, which you're also trying to pass to eval - which is bound to fail in itself, but even before that your code is trying to add the existing text string to the actual function value, which is impossible.
Judging from the last line of your sample, you have a function called process() somewhere. Yet you try to access it as if it were an iterable in the line if encodinghex in process. To fix the error, change the name of either the function or the iterable.