I am trying to use Tkinter to build a simple GUI app which imports data and performs some analysis. The GUI has just four labels and four buttons side by side. When you press the button, you should get a File Dialog prompt. However, whenever I run the script (see below), Python calls all button commands at startup, and then the buttons don't work afterwards. Even if I write the code without a class, the same thing happens. How do I get it to stop doing this? Thanks!
Code:
import numpy import scipy from Tkinter import * import tkFileDialog as tkf filenames = {} class App: def __init__(self, master): frame = Frame(master) frame.pack() self.Name0 = Label(frame, text = "Initial Data", width=30).grid(row=0, sticky=W,columnspan=2) self.Name1 = Label(frame, text = "After Change #1", width=30).grid(row=1, sticky= W,columnspan=2) self.Name2 = Label(frame, text = "After Change #2", width=30).grid(row=2,sticky=W,columnspan=2) self.Name3 = Label(frame, text = "Current State", width=30).grid(row=3,sticky=W,columnspan=2) self.Butt0 = Button(frame, text = "Select", command=tkf.askopenfile()).grid(row=0,column=2) self.Butt1 = Button(frame, text = "Select", command=tkf.askopenfile()).grid(row=1,column=2) self.Butt2 = Button(frame, text = "Select", command=tkf.askopenfile()).grid(row=2,column=2) self.Butt3 = Button(frame, text = "Select", command=tkf.askopenfile()).grid(row=3,column=2) root = Tk() app = App(root) root.mainloop()
Comment