470,638 Members | 1,590 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,638 developers. It's quick & easy.

Stuck on some "Entry pack" code for GUI

Please ignore the rest of the code, except for the highlighted part (or the line 'ent1=Entry(topf, width=25)' to line 'ent1.insert(INSERT, wrong, if you cannot see the color). You can copy this into Python and make sure you have the GIF file in the same dir. Also, make sure that you have PIL installed.

I cannot get this to work. I get an error after running it and what I'm trying to do it to evaluate what the person enters in the box for the capital of Alabama. I want the user to enter the capital and if it's not right, I want the program to tell them within that box. Apparently, Python does not like the "0.0" entry within the box. Why is this not working?

from Tkinter import *
import ImageTk
class Gui(Frame):

def lab(self):
# A generic text label for the frame
self.lab1 = Label(base, text = "Text for label") #text will be reset later

def but(self):
# A generic button for the frame
self.but1 = Button(bottom, text="Take the quiz") #text and command to be set later

def labR(self):
# A generic text label for the right frame
self.lab1R = Label(R, text = "Text for label") #text will be reset later
self.lab1R.pack(side = TOP)

#def butL(self):
# A generic button for the left frame
#self.but1L = Button(L, text="text on button") #text and command to be set later
#self.but1L.pack(side = LEFT)

def butR(self):
# A generic button for the right frame
self.but1R = Button(RB, text="text on button") #text and command to be set later
self.but1R.pack(side = LEFT)

#def entcap(None):
# A generic text entry for the left frame
#self.entcap1 = Entry(width=25) #width can be changed later
#self.entcap1.pack(side = BOTTOM)

def entR(self):
# A generic text entry for the right frame
ent1R = Entry(RB, width=20) #width can be changed later
ent1R.pack(side = TOP)

def txtL(self):
# A generic text box for the left frame
self.txt1L = Text(L, width=100, height=5, wrap=WORD)
self.txt1L.pack(side = BOTTOM)

def txtR(self):
# A generic text box for the right frame
self.txt1R = Text(R, width=100, height=5, wrap=WORD, padx=5, pady=5)
self.txt1R.pack(side = TOP)

def rdbut(self):

self.states = StringVar()
Radiobutton(base, text="Alabama", variable=self.states, value="AL").grid(row=20, column=0, sticky=W)
Radiobutton(base, text="Arkansas", variable=self.states, value="AK").grid(row=20, column=1, sticky=W)
Radiobutton(base, text="Florida", variable=self.states, value="FL").grid(row=20, column=2, sticky=W)
Radiobutton(base, text="Georgia", variable=self.states, value="GA").grid(row=25, column=0, sticky=W)
Radiobutton(base, text="Kentucky", variable=self.states, value="KY").grid(row=25, column=1, sticky=W)
Radiobutton(base, text="Louisiana", variable=self.states, value="LA").grid(row=25, column=2, sticky=W)
Radiobutton(base, text="Mississippi", variable=self.states, value="MS").grid(row=30, column=0, sticky=W)
Radiobutton(base, text="North Carolina", variable=self.states, value="NC").grid(row=30, column=1, sticky=W)
Radiobutton(base, text="South Carolina", variable=self.states, value="SC").grid(row=30, column=2, sticky=W)
Radiobutton(base, text="Tennessee", variable=self.states, value="TN").grid(row=35, column=0, sticky=W)
Radiobutton(base, text="Virginia", variable=self.states, value="VA").grid(row=35, column=1, sticky=W)
Radiobutton(base, text="West Virginia", variable=self.states, value="WV").grid(row=35, column=2, sticky=W)

def stateget(self):
state = self.states.get()
if state == "AL":
top = Toplevel()
top.title("Alabama Capital Quiz")
topf = Frame(top)
topb = Frame(top)
pct = ImageTk.PhotoImage(file="AL.gif")
var = Canvas(topb, height=250, width=250)
img = var.create_image(10, 10, anchor=N, image=pct)
# Now I add a text box
#txtbx2 = Text(topf, height=5, width=40, bg="yellow", wrap=WORD)
#txtbx2.insert(INSERT, message2)
close = Button(topb, text="Close", command=top.destroy)
ent1=Entry(topf, width=25)
ent1.insert(INSERT, "What is the capital of Alabama?")
name = ent1.get()
right = "Correct!!!"
wrong = "No, please try again."
if name == "montgomery":
ent1.delete(0.0, END)
ent1.insert(INSERT, right)
ent1.delete(0.0, END)
ent1.insert(INSERT, wrong)

root = Tk()
root.title("US Southeast Regional Quiz")
gui = Gui(root)
base = Frame(root)

gui.lab1.configure(text="Welcome to the Southeast US State Quiz!")

# I will bring in another label explaining what I want
gui.lab1["text"]="Please select a state to begin and click on the 'Take the quiz' button below."

# Now for the radiobuttons displayed with the updatemsg textbox

# I Need a frame for my buttons
bottom = Frame(base)

# To get out of the program
gui.but1.configure(text="Exit", command=gui.quit)

# To run the msg function
gui.but1.configure(text="Take the Quiz", command=gui.stateget)


Jul 19 '05 #1
0 1290

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by seeker | last post: by
10 posts views Thread by Lung.S.wu | last post: by
1 post views Thread by Stoney L | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.