I am new to GUI programming and i'm trying to get this python program to work. What would be the correct way to call function start()
so that it updates the two canvases. My code looks like this.
from Tkinter import *
class TKinter_test(Frame):
def __init__(self,parent):
Frame.__init__(self,parent)
self.parent = parent
self.initUI()
user_reply = 0
def accept(self):
self.user_reply = 1
def decline(self):
self.user_reply = 2
def initUI(self):
BtnFrame = Frame (self.parent)
BtnFrame.place(y=450, x=20)
canvasFrame = Frame(self.parent)
canvasFrame.place(y = 200)
canvas_1 = Canvas(canvasFrame, width = "220", height ="200")
canvas_2 = Canvas(canvasFrame, width = "220", height ="200")
canvas_1.pack(side = LEFT)
canvas_2.pack(side = RIGHT)
textfield_1 = canvas_1.create_text(30,50,anchor = 'w', font =("Helvetica", 17))
textfield_2 = canvas_2.create_text(30,50,anchor = 'w', font =("Helvetica", 17))
Accept = Button(BtnFrame, text="Friends!", width=25, command = self.accept)
Decline = Button(BtnFrame, text="Not friends...", width=25, command = self.decline)
Accept.pack(side = LEFT)
Decline.pack(side = RIGHT)
def ask_user(self,friend_1,friend_2):
timer = 0;
while(timer == 0):
if(self.user_reply == 1):
print friend_1 + " and " + friend_2 + " are friends!"
self.user_reply = 0
timer = 1;
elif(user_reply == 2):
print friend_1 + " and " + friend_2 + " are not friends..."
self.user_reply = 0
timer = 1
def start(self):
listOfPeople = ["John","Tiffany","Leo","Tomas","Stacy","Robin","Carl"]
listOfPeople_2 = ["George","Jasmin","Rosa","Connor","Valerie","James","Bob"]
for friend_1 in listOfPeople:
for friend_2 in listOfPeople_2:
ask_user(friend_1,friend_2)
print "Finished"
def main():
root = Tk()
root.geometry("500x550")
root.wm_title("Tkinter test")
app = TKinter_test(root)
root.mainloop()
if __name__ == '__main__':
main()
I would like to use in ask_user something that updates textfield_1 and 2. Something like textfield_1.itemconfigure(text = friend_1)
and I would prefer not to use threads.
Thank you.