Python Forum
Global Variable in Event Function? What am I doing wrong here?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Global Variable in Event Function? What am I doing wrong here?
#2
Okay well the first mistake is using a Global Variable -- any programmer that has experienced the pain of global variables will tell never use one unless absolutely necessary which means most of the time do not use one no matter how tempting it might seem. Take extra time to figure out how to not make it global as that will save you immense amount of time later on.

To fix your code though delete the entire global statement on line 18 as it is not needed in this context

self. anything declared within the __init__ function causes that variable to be available to the ENTIRE class through out the lifetime of that instance of that class object.

not knowing Tkinter though I cannot speak to your usage of the Checkbutton's Signal and Slot mechanics if after deleting that line if it still does not seem to work I would strongly suggest you looking into your usage of the Checkbutton's event handling syntax -- either that or perhaps a Tkinter aficionado will chime in
Reply


Messages In This Thread
RE: Global Variable in Event Function? What am I doing wrong here? - by Denni - Nov-13-2019, 02:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] [Solved]Help getting variable from Function in PyQt Extra 6 1,515 Jul-06-2022, 10:19 PM
Last Post: Extra
  [Tkinter] Passing variable to function. KDog 2 2,166 May-25-2021, 09:15 PM
Last Post: KDog
  return a variable from a function snakes 3 2,813 Apr-09-2021, 06:47 PM
Last Post: snakes
  [Tkinter] tkinter global variable chalao_adda 6 11,094 Nov-14-2020, 05:37 AM
Last Post: chalao_adda
  Call local variable of previous function from another function with Python3 & tkinter Hannibal 5 4,456 Oct-12-2020, 09:16 PM
Last Post: deanhystad
  [PyQt] How to write event function Squalo 0 1,396 Sep-17-2020, 11:04 AM
Last Post: Squalo
  [Tkinter] Unable to Access global Variable when switching between frames tziyong 1 3,485 Nov-03-2019, 01:08 AM
Last Post: balenaucigasa
  [WxPython] How to return a variable from an event handler Shaba1 2 3,946 Jun-13-2019, 02:47 PM
Last Post: Shaba1
  tkinter - global variable not working albry 2 7,068 Jan-26-2019, 04:22 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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