[Tutor] help
Isaac Parkes
isaac.parkes at googlemail.com
Mon Nov 19 19:07:10 CET 2012
hi,
I'm quite new to python and have just made a program that makes a GUI but
when i open it it says there are some errors. I can't find any :( if you
find any problems could you tell me ASAP
# Match finder
from TKinter import *
import random
girls = ['Ellie', 'Maddy', 'Ursula', 'Annie', 'Stella',
'Kimberely', 'Flora', 'Hannah', 'Bella', 'Ella',
'Rosa', 'Olivia', 'Liya', 'Emma', 'Irene']
boys = ['Charlie', 'sion', 'Mikey', 'Jem', 'Matthew', 'Ethan', 'Kainan',
'Louis', 'Jack', 'Abel', 'Alex', 'Tom', 'Will', 'James', 'Isaac']
class Application(Frame):
""" GUI application which can reveal your perfect match. """
def __init__(self, master):
""" Initialize the frame. """
Frame.__init__(self, master)
self.grid()
self.create_widgets()
def create_widgets(self):
""" Create button, text, and entry widgets. """
# create instruction label
self.inst_lbl = Label(self, text = "Enter details below to find out
your perfect match")
self.inst_lbl.grid(row = 0, column = 0, columnspan = 2, sticky = W)
# create label for name
self.pw_lbl = Label(self, text = "Name: ")
self.pw_lbl.grid(row = 1, column = 0, sticky = W)
# create entry widget to accept name
self.pw_ent = Entry(self)
self.pw_ent.grid(row = 1, column = 1, sticky = W)
# create variable for single, favorite type of movie
self.favorite = StringVar()
# create boy radio button
Radiobutton(self,
gender = "Boy",
variable = self.favorite,
gender1 = "Boy.",
command = self.update_text
).grid(row = 2, column = 0, sticky = W)
# create girl radio button
Radiobutton(self,
gender = "Girl",
variable = self.favorite,
gender1 = "Girl.",
command = self.update_text
).grid(row = 3, column = 0, sticky = W)
# create submit button
self.submit_bttn = Button(self, text = "Submit", command =
self.reveal)
self.submit_bttn.grid(row = 2, column = 0, sticky = W)
# create text widget to display message
self.secret_txt = Text(self, width = 35, height = 5, wrap = WORD)
self.secret_txt.grid(row = 3, column = 0, columnspan = 2, sticky =
W)
def update_text(self):
""" Display message based on match. """
message = "Your perfect match is: ",
if gender == 'boy':
choice = random.choice(girls)
else:
choice = random.choice(boys)
message += choice
self.secret_txt.delete(0.0, END)
self.secret_txt.insert(0.0, message)
# main
root = Tk()
root.title("Match finder")
root.geometry("250x150")
app = Application(root)
root.mainloop()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121119/011009f5/attachment-0001.html>
More information about the Tutor
mailing list