The short answer is the
using
Note: see Namespace flooding with * imports
The code rewritten answer, using classes and an
pop_label
only exists locally to ACwindowdriver
using
global
in GUI code is not ideal, I prefer to code GUI using classes.Note: see Namespace flooding with * imports
The code rewritten answer, using classes and an
IntVar
import tkinter as tk class AcWindowDriver(tk.Toplevel): def __init__(self, count, *args, **kwargs): super().__init__(*args, *kwargs) self.title("My Popup") self.geometry("150x200+00+00") self.overrideredirect(True) # Borderless self.config(bg="black") self.count = count pop_label = tk.Label( self, bg="green", fg="white", font=("helvetica", 12), textvariable=count ) pop_label.config(text=count) pop_label.grid(row=1, column=0, pady=10) my_frame = tk.Frame(self, bg="black") my_frame.grid(row=1, column=1, pady=10) heatdriver_btn = tk.Button( my_frame, command=self._on_heatdriver_btn, bg="black" ) heatdriver_btn.grid(row=2, column=2, pady=10) colddriver_btn = tk.Button( my_frame, command=self._on_colddriver_btn, bg="black" ) colddriver_btn.grid(row=3, column=2, pady=10) def _on_heatdriver_btn(self): current_count = self.count.get() self.count.set(current_count + 1) def _on_colddriver_btn(self): current_count = self.count.get() self.count.set(current_count - 1) class MainFrame(tk.Frame): def __init__(self, *args, **kwargs): super().__init__(*args, *kwargs) self.count = tk.IntVar(self, 20) self.ac_window_driver = None destroy_btn = tk.Button(self, text="destroy", command=self._on_destroy_btn) destroy_btn.place(x=1, y=1) ac_driver_btn = tk.Button( self, text="ACwindowdriver", command=self._on_ac_driver_btn ) ac_driver_btn.pack(pady=50) my_label = tk.Label(self, textvariable=self.count) my_label.pack(pady=20) def _on_destroy_btn(self): if not self.ac_window_driver: return self.ac_window_driver.destroy() self.ac_window_driver = None def _on_ac_driver_btn(self): if self.ac_window_driver: return self.ac_window_driver = AcWindowDriver(self.count, self) def main(): app = tk.Tk() app.geometry("300x300") main_frame = MainFrame(app) main_frame.pack() app.mainloop() if __name__ == "__main__": main()