473,395 Members | 2,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Stuck on some "Entry pack" code for GUI

BW
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
self.lab1.grid(columnspan=3)

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

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)
topf.pack()
topb = Frame(top)
topb.pack()
pct = ImageTk.PhotoImage(file="AL.gif")
var = Canvas(topb, height=250, width=250)
img = var.create_image(10, 10, anchor=N, image=pct)
var.pack()
#top.geometry("500x500")
# Now I add a text box
#txtbx2 = Text(topf, height=5, width=40, bg="yellow", wrap=WORD)
#txtbx2.pack(side=TOP)
#txtbx2.insert(INSERT, message2)
close = Button(topb, text="Close", command=top.destroy)
close.pack(side=RIGHT)
ent1=Entry(topf, width=25)
ent1.insert(INSERT, "What is the capital of Alabama?")
ent1.pack()
name = ent1.get()
right = "Correct!!!"
wrong = "No, please try again."
if name == "montgomery":
ent1.delete(0.0, END)
ent1.insert(INSERT, right)
else:
ent1.delete(0.0, END)
ent1.insert(INSERT, wrong)


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

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

# I will bring in another label explaining what I want
gui.lab()
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
gui.rdbut()
#gui.updatemsg()

# I Need a frame for my buttons
bottom = Frame(base)
bottom.grid(row=99)

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

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


root.mainloop()

Jul 19 '05 #1
0 1447

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Don G | last post by:
Within the menu for my site, I have inserted 'class="current"' within the link for the current page. So the link looks somthing link: <li><a href="index.php" class="current">Home</a></li> The...
1
by: seeker | last post by:
I need to develop some fairly basic data entry screens to add, update and delete records in a SQL Server 2000 database. Is anyone aware of some free or shareware VB.NET 2003 code that can be...
3
by: D Denholm | last post by:
I am a Access newbie... Hopefully somebody can help me figure this out. I have a database that looks like: Asset Economic Minimum ----- ---------------- 10555 ...
0
by: cherryparadise001 | last post by:
Hi All, I have moved an asp system from Window Server 2000 to Window Server 2003 recently. Many error occured and most of them are unable to get the control's value in the page. I am newbie to...
8
by: Jeremy | last post by:
If we have a table with say 3 rows in it and one of the columns contains a checkbox such as <table> <tr> <td><input type="checkbox" name="ch_fld"></td> </tr> <tr> <td><input type="checkbox"...
10
by: Lung.S.wu | last post by:
Hi all, It is a history question. Recently, I read the book "C A reference manual, third edition". In this book, it list all C language keyword, and one is "entry". I know it is omitted from...
2
by: Rymfax | last post by:
I have an application that will be used on both XP and Vista. One of the things this application needs to do is determine the exact operating system it is on. To get the correct "flavor" of Vista...
1
by: HappyChapZA | last post by:
Hi all, I have the following code which displayes properties to let when searched for by "City/Town", "Suburb", "Type" and then between two "Rental" amounts. I would like to also include filtering...
3
by: ElBeardo | last post by:
Hello, I´m new to Python.. so this is a newbee question. I´d like to put the value enterd in the entryfield in a variable. I´m trying to build a calculator with python and TKinter, coding it in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.