Python Forum
Class Struggle: Connecting a Method to an Outside Variable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Class Struggle: Connecting a Method to an Outside Variable
#5
using myVar as a name for a widget is misleading.
the textvariable attribute should point to a tk.StringVar which you can preset using
that attribute and a tk.StringVar.
The StringVar can be set externally with string_var_name.set() (replace string_var_name with actual name)
It can be initally be set within the button definition
string_var_name = StringVar()
self.myVar = Button(self.position, text=self.text, textvariable=string_var_name, command=self.cmd)
Again, rename myVar to a meaningful widget name.
Also to be in conformance with PEP8, don't use camel case, use underscore instead
see: http://effbot.org/tkinterbook/variable.htm

Sorry for the edits, just got up
Reply


Messages In This Thread
RE: Class Struggle: Connecting a Method to an Outside Variable - by Larz60+ - Jan-23-2018, 10:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Selenium big struggle Troop 2 1,732 Apr-25-2020, 10:47 AM
Last Post: Troop

Forum Jump:

User Panel Messages

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