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
#4
I'm not sure it's a good idea to remove the explicit keywords when calling tkinter's methods, because the order of the arguments may be incorrect. Also you may need to keep a reference to the object you created in the init method, for example
class btn(object):
    def __init__(self, pos, txt, cmd, row, col, colspan, sticky):
        self.position = pos
        self.text = txt
        self.command = cmd
        self.row = row
        self.column = col
        self.columnspan = colspan
        self.sticky = sticky
 
        self.myVar = Button(self.position, text=self.text, command=self.cmd)
        self.myVar.grid(row=self.row, column=self.column, columnspan=self.columnspan, sticky=self.sticky)
Concerning myVar.bind('Button-1', myMethod), this call binds the event 'Button-1', which is the left mouse button event to the method myMethod for the tkinter widget myVar. Of course you can use this call only if there are a widget and a method named myVar and myMethod in the scope of the call.
Reply


Messages In This Thread
RE: Class Struggle: Connecting a Method to an Outside Variable - by Gribouillis - Jan-23-2018, 06:52 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Selenium big struggle Troop 2 1,723 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