| | |
Class issue.
![]() |
•
•
Join Date: Oct 2008
Posts: 5
Reputation:
Solved Threads: 0
So I am getting into the swing of python in my class, and am currently trying to take a program from an example, and making it much more condensed. The issue I am having, is there are many classes for a tkinter guessing game.
The class question 5 is one of 5(obviously) that checks for a right answer. I was trying to make a class that would dynamically check based on what entry box I was entering into. How would I get that to work with the class, or is it even possible?
def question5():
if entry5.get() in ["Samus", "samus", "Metroid", "metroid", "Prime", "prime", "Metroid Prime", "metroid prime"]:
answerlabel5['text']= "Its the amazing Metroid game heroine Samus, good call!"
else:
answerlabel5['text']= "Sigh.. try again."
def question(butnum):
print "calling proc" #shows space in output to see what is going in
print "you submitted", butnum #trying to find what output is happening.
"""if (ent[i]).get() in ans[i]:
(a[i])['text'] = acor[i]
else:
(a[i])['text'] = ahint[i]""" #" was an attempt to get it to work.
for i in range(0, 5):
images[i] = Label(image=images[i]).pack()
ent[i] = Entry().pack()
sub[i] = Button(text="Submit Answer",command=(lambda: question('i')), fg="white",bg="grey50", font=('impact',10)).pack()
ans[i] = Label(text="", bg="white", font=('impact',10)).pack()The class question 5 is one of 5(obviously) that checks for a right answer. I was trying to make a class that would dynamically check based on what entry box I was entering into. How would I get that to work with the class, or is it even possible?
•
•
Join Date: Oct 2008
Posts: 5
Reputation:
Solved Threads: 0
Eh yah, sorry wasn't thinking straight when I made this post last night. What I meant was:
The procedure question 5 is one of 5(obviously) that checks for a right answer. I was trying to make a procedure that would dynamically check based on what entry box I was entering into. How would I get that to work with the procedure, or is it even possible?
Sorry for the confusion.
The procedure question 5 is one of 5(obviously) that checks for a right answer. I was trying to make a procedure that would dynamically check based on what entry box I was entering into. How would I get that to work with the procedure, or is it even possible?
Sorry for the confusion.
When in doubt run a simplified test code:
python Syntax (Toggle Plain Text)
# test Tkinter Entry import Tkinter as tk def question5(event): if entry1.get().lower() in ["samus", "metroid", "prime", "metroid prime"]: label2['text'] = "Its the amazing Metroid game heroine Samus, good call!" else: label2['text'] = "Sigh.. try again." root = tk.Tk() # first entry with label label1 = tk.Label(root, text='Enter heroine:') label1.grid(row=0, column=0) entry1 = tk.Entry(root, bg='yellow', width=50) entry1.grid(row=1, column=0, padx=5) label2 = tk.Label(root, text=' ', fg='red') label2.grid(row=2, column=0, pady=5) # start cursor in enter1 entry1.focus() # value has been entered in enter1 now press return key to check content entry1.bind('<Return>', question5) root.mainloop()
No one died when Clinton lied.
•
•
Join Date: Oct 2008
Posts: 45
Reputation:
Solved Threads: 6
I'll write up a better explination later, but here is a class that would create the widget and check your answers:
you can see the call to the class there at the end.
python Syntax (Toggle Plain Text)
from Tkinter import * class question(): def __init__(self, parent, q_text, a_list, correct, incorrect): self.frame = Frame(parent) self.q_text = q_text self.a_list = a_list self.correct = correct self.incorrect = incorrect Label(self.frame, text=self.q_text).grid(row=0, column=0) self.entry = Entry(self.frame) self.label = Label(self.frame) self.entry.grid(row=1, column=0) self.label.grid(row=1, column=1) Button(self.frame, text='check', command=self.check).grid(row=2, column=1) def grid(self, y, x, yspan=1, xspan=1): self.frame.grid(row=y, column=x, rowspan=yspan, columnspan=xspan) def pack(self): self.frame.pack() def check(self): self.answer = self.entry.get().lower() for x in self.a_list: if self.answer.find(x)!=-1: self.label['text'] = self.correct return 1 self.label['text'] = self.incorrect return 0 root = Tk() x = question(root, 'Which Character is this:', ['samus', 'metriod', 'prime'], "That's Correct!", "That's Incorrect!") x.grid(0, 0) root.mainloop()
you can see the call to the class there at the end.
Last edited by tyincali; Oct 28th, 2008 at 4:23 pm.
![]() |
Similar Threads
- class designs in java-air traffic controller system--need help!! (Java)
- Spyware/Pop-up Issue (Viruses, Spyware and other Nasties)
- Unknown Internet Explorer Issue (Viruses, Spyware and other Nasties)
- 2020 Search Still An Issue. (Viruses, Spyware and other Nasties)
- Keyboard Issue: New IE window opens when using the "L" key. (Viruses, Spyware and other Nasties)
- bridge.dll issue (Windows NT / 2000 / XP)
- redhat 8.0 firewall issue (*nix Software)
Other Threads in the Python Forum
- Previous Thread: Problems with Vista and wxPython
- Next Thread: Python
| Thread Tools | Search this Thread |
alarm anydbm app assignment beginner bluetooth character cipher cmd conversion coordinates corners curves customdialog cx-freeze data decimals definedlines development directory events excel exe feet file float format function generator getvalue gnu halp handling homework http ideas input ip itunes keycontrol leftmouse line linux list lists loan loop maintain maze millimeter module mouse number numbers output parsing path prime programming push py2exe pygame pymailer python queue random rational raw_input recursion recursive schedule screensaverloopinactive script searchingfile slicenotation sqlite ssh string strings sudokusolver text time tlapse tooltip tuple type ubuntu unicode url urllib urllib2 variable ventrilo vigenere web webservice wikipedia wxpython xlib xlwt






