After already assigning a textvariable to a widget, how do I remove it? widget.config(textvariable=None)
just isn't working. Couldn't find anything on google or here.
Asked
Active
Viewed 215 times
2

vl3005
- 45
- 4
-
1Why would you do that? – Thingamabobs Oct 03 '20 at 15:11
-
An alternative to removing the widget all together cause it messes up the grid. All the `grid_propagate(0)`'s in the world couldn't help me, so I figured I'll just remove the textvariable and empty the text, but nothing happens so I'm thinking there's some special way to do that. – vl3005 Oct 03 '20 at 15:38
-
are you familiar with the `grid_forget()` method. I think you have a layout problem not with your variable. https://stackoverflow.com/questions/63536505/how-do-i-organize-my-tkinter-appllication/63536506#63536506 – Thingamabobs Oct 03 '20 at 15:40
-
I am. It's just that if I do that, the entire layout goes to hell. No matter what I do. `rowconfigure(n, weight=x)` and `grid_propagate(0)` just don't help. It's as if tkinter is not behaving as promised. – vl3005 Oct 03 '20 at 15:55
-
It does if you know how to do it. If you could write a Question about it I would answer you, but need to see in what kind of context you are to make valid points. – Thingamabobs Oct 03 '20 at 15:58
-
You mean a post new Question? Or just comment the code here? – vl3005 Oct 03 '20 at 16:03
-
Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/222457/discussion-between-atlas435-and-vl3005). – Thingamabobs Oct 03 '20 at 16:03
1 Answers
2
Assign your variable to an empty string to achive this.
import tkinter as tk
root = tk.Tk()
var = tk.StringVar()
label = tk.Label(root, textvariable=var)
label.pack()
print(f"var= {label['textvariable']}")
label.config(textvariable='')
print(f"var= {label['textvariable']}")
root.mainloop()

Thingamabobs
- 7,274
- 5
- 21
- 54
-
As you can see in my example it works. Show me a minimal exampel of your code – Thingamabobs Oct 03 '20 at 15:38
-
1It didn't work the way you wrote it, but after adding `text=''` to the config method, it did. :) Thank you!! Couldn't edit my original comment cause of a false click on the "save edit" button..... – vl3005 Oct 03 '20 at 15:48