Python Forum
[Tkinter] Can't update label in new tk window, object has no attribute
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Can't update label in new tk window, object has no attribute
#1
Hi, I have this code but i get the error "object has no attribute".

from tkinter import *

root = Tk()

root.geometry("300x300")

count = 20

pop_label = None

def ACdriver(option):
#	pop.destroy()
	global count
	if option == "UP":
		count = count + 1
	else:
		count = count - 1
	my_label.config(text=count)
	pop_label.config(text=count)

def ACwindowdriver():
	global pop
	pop = Toplevel(root)
	pop.title("My Popup")
	pop.geometry("150x200+00+00")
	pop.overrideredirect(True) #Borderless
	pop.config(bg="black")


	pop_label = Label(pop, bg="green", fg="white", font=("helvetica", 12))
	pop_label.config(text=count)
	pop_label.grid(row=1, column=0, pady=10)


	my_frame = Frame(pop, bg="black")
	my_frame.grid(row=1, column=1, pady=10)

	heatdriver = Button(my_frame, command=lambda: ACdriver("UP"), bg="black")
	heatdriver.grid(row=2, column=2, pady=10)

	colddriver = Button(my_frame, command=lambda: ACdriver("DOWN"), bg="black")
	colddriver.grid(row=3, column=2, pady=10)

def destroy():
	pop.destroy()


destroy_button = Button(root, text="destroy", command=destroy)
destroy_button.place(x=1, y=1)

ACdriver_button = Button(root, text="ACwindowdriver", command=ACwindowdriver)
ACdriver_button.pack(pady=50)

my_label = Label(root, text="")
my_label.pack(pady=20)



root.mainloop()
I am trying to update the number inside the new tk window called "pop" but the number only updates after i press "destroy" and "ACwindowdriver" again. When i press one button inside the window pop i get the error "'NoneType' object has no attribute 'config'".

Thankfull for all help.

Kind regards
Tom

Attached Files

Thumbnail(s)
       
Reply


Messages In This Thread
Can't update label in new tk window, object has no attribute - by tompranks - Aug-27-2022, 09:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 537 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  'NoneType' object has no attribute 'get' zunebuggy 8 1,396 Oct-13-2023, 06:39 PM
Last Post: zunebuggy
  [Tkinter] Update label if there are no records in treeview TomasSanchexx 1 948 Aug-20-2023, 04:45 PM
Last Post: menator01
  tkinter AttributeError: 'GUI' object has no attribute pfdjhfuys 3 1,584 May-18-2023, 03:30 PM
Last Post: pfdjhfuys
  PysimpleGUI window update dynamically SamLiu 6 4,062 Apr-05-2023, 02:32 PM
Last Post: SamLiu
  [Kivy] Windows 10: AttributeError: 'WM_PenProvider' object has no attribute 'hwnd' mikepy 1 2,343 Feb-20-2023, 09:26 PM
Last Post: deanhystad
  AttributeError: 'NoneType' object has no attribute 'get' George87 5 15,523 Dec-23-2021, 04:47 AM
Last Post: George87
  [PyQt] AttributeError: 'NoneType' object has no attribute 'text' speedev 9 11,473 Sep-25-2021, 06:14 PM
Last Post: Axel_Erfurt
  update text variable on label with keypress knoxvilles_joker 3 4,951 Apr-17-2021, 11:21 PM
Last Post: knoxvilles_joker
  [Tkinter] AttributeError: '' object has no attribute 'tk' Maryan 2 14,706 Oct-29-2020, 11:57 PM
Last Post: Maryan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020