I'm new to GUIs and just learning how to use Tkinter. I wrote a python program to put the students in my class into pairs for my seating charts. The program itself runs fine; the problem is the tkinter gui. I've tried to make the button generate and display a new set of pairs each time. Instead, the GUI will display the first set of pairs as soon as I open it, without even pressing the button. The button does nothing. If I run it in console, I don't get any error messages or anything printed to console.
At Button commands in Tkinter I saw an answer to do with using lambda. When I tried it, the label will initially be blank. It will display the pairs when the button is pressed the first time, as expected, but on subsequent presses it just makes the label blank again.
I'm not sure what the problem is. Can you help me? Here is the code:
from Tkinter import *
from SeatingChart import *
root = Tk()
class App:
def __init__(self, master):
self.win = Frame(master)
self.win.pack()
self.d = Label(self.win, text = "", width=140)
self.d.pack()
self.b = Button(self.win, text="Pair Up!", command=self.display_pairs(roster))
self.b.pack()
def display_pairs(self, l):
self.d.config(text=pair(roster))
app = App(root)
mainloop()