-1

First of all, I know that there are tons of threads about this issue, but I have still made 0 progress on this, none of the solutions work. I even created a minimal example with 9 lines of code and doesnt matter what I do, the label text wont change:

root = tkinter.Tk()

screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()

root.geometry("500x50" + "+" + str(screen_width - 520) + "+" + str(screen_height - 140))
root.title("POE Price Checker")
rootLabelHeader = tkinter.Label(root, text = "Currently searching:").pack()

labelText = tkinter.StringVar()
labelText.set("Nothing")
rootLabelInfo = tkinter.Label(root, text = labelText.get(), width=90).pack()

#rootLabelInfo.configure(text="New String") # Nope
#rootLabelInfo.config(text="New String") # Nope

labelText.set("Doesnt Work")
labelText.get()

#root.after(1000, ListenToInput)
root.mainloop()

First I have tried using StringVar, but nothing happens, it never changes the text to "Doesnt Work", also no errors are shown.

Then I tried using:

rootLabelInfo.configure(text="New String")
rootLabelInfo.config(text="New String")

Both give me NoneType object has no attribute config.

Roman
  • 3,563
  • 5
  • 48
  • 104
  • 1
    `rootLabelHeader = tkinter.Label(root, text = "Currently searching:")` ; `rootLabelHeader.pack()` now can configure the label – Masoud Jun 17 '19 at 17:33

1 Answers1

1

rootLabelInfo = tkinter.Label(root, text = labelText.get(), width=90).pack() stores the packed object function (which will return None) to rootLabelInfo

If you plan on using the widget later, do it in two lines:

rootLabelInfo = tkinter.Label(root, text = labelText.get(), width=90)
rootLabelInfo.pack()

Another method is using a StringVar and setting the textvariable attribute:

import tkinter

root = tkinter.Tk()

screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()

root.geometry("500x50" + "+" + str(screen_width - 520) + "+" + str(screen_height - 140))
root.title("POE Price Checker")
rootLabelHeader = tkinter.Label(root, text = "Currently searching:").pack()

labelText = tkinter.StringVar()
labelText.set("Nothing")
print(labelText.get())
rootLabelInfo = tkinter.Label(root, textvariable = labelText, width=90).pack()

labelText.set("New String")
print(labelText.get())

#root.after(1000, ListenToInput)
root.mainloop()
tgikal
  • 1,667
  • 1
  • 13
  • 27