I wold like to be able to generate buttons from a list in a file.
How would I go about making each button have a different command,
Lets say make the button print its label instead of print "."
The problem I have is I don't know what the list is going to be until
it is opened or how big so I carnet make a def for each.
And I don't know how to do it with a loop
Thanks
------Code-------
from Tkinter import *
class App:
def __init__(self, root):
self.DisplayAre aListsFrame = Frame(root)
self.DisplayAre aListsFrame.pac k()
Lists = ["A1","B2","C3", "D4"]
for i in Lists:
self.DisplayAre aListButton = Button(
self.DisplayAre aListsFrame,
text=i,
command=self.Li stButtonCommand )
self.DisplayAre aListButton.pac k(side=LEFT,pad x=10)
def ListButtonComma nd(self):
print "."
root = Tk()
app = App(root)
root.mainloop()
How would I go about making each button have a different command,
Lets say make the button print its label instead of print "."
The problem I have is I don't know what the list is going to be until
it is opened or how big so I carnet make a def for each.
And I don't know how to do it with a loop
Thanks
------Code-------
from Tkinter import *
class App:
def __init__(self, root):
self.DisplayAre aListsFrame = Frame(root)
self.DisplayAre aListsFrame.pac k()
Lists = ["A1","B2","C3", "D4"]
for i in Lists:
self.DisplayAre aListButton = Button(
self.DisplayAre aListsFrame,
text=i,
command=self.Li stButtonCommand )
self.DisplayAre aListButton.pac k(side=LEFT,pad x=10)
def ListButtonComma nd(self):
print "."
root = Tk()
app = App(root)
root.mainloop()
Comment