1

In this example, that I used from http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm, how could you pass in more variables to the function callback. Say you wanted to pass in a dict that you created and use that dict, how could you do that without calling global variables.

from Tkinter import *

root = Tk()

def callback(event):
    print "clicked at", event.x, event.y

frame = Frame(root, width=100, height=100)
frame.bind("<Button-1>", callback)
frame.pack()

root.mainloop()

Newb here, might have some awkward phrasing, feel free to ask for clarification.

Dta
  • 35
  • 1
  • 9

1 Answers1

0

Here are two possible ways.

  1. You can put your 'callback' function in a class, and use self to pass in self-defined variables
  2. You can set all your variables in another module file and import it to this file. Since variables from another file have been imported to this namespace, you can use them without passing into 'callback' function, just the same as global variables.
Stephen Lin
  • 4,852
  • 1
  • 13
  • 26