| | |
GUI with calculator.
![]() |
•
•
Join Date: Feb 2007
Posts: 55
Reputation:
Solved Threads: 4
G'day,
I've been working with Pyhton for about six months and have been wanting to put a program into a seperate Tkinter GUI but have had no luck.
I need to have a Tk GUI that has vertical scrolling exactly like the normal IDE except that positioned in the upper right corner will sit a tiny calculator.
This tiny calculator does not need to have the "x" or the "+" or the "-" etc or any of the other signs at all.
The reason is because the program is a simple high\low game and only needs to have the numbers from 0 to 9. The only other functions the calculator needs is the backspace (in case of mistakes) and an entry button to enter the number onto the left hand side of the page. Also a quit button to finish.
I have XP on my Compaq Evo desktop.
The program works fine except that when I try to put it into a different GUI all sorts of problems occur. Is this because I need to use pyw instead of py? Or do I just import it as is into the new GUI? I realize that "run==exit" will have to be replaced by quit or suchlike.
Thanks for any help (this is my first time on any forum).
import random
number = random.randint(1, 10000)
running = True
run=""
attempts=0
while running:
guess = int(raw_input('Enter an integer : '))
print
attempts = attempts + 1
WORDS=("Get it before ten tries or the world will explode!",\
"The next one is the 70th try, hurry!", "400 guesses later...",\
"A guess a day keeps the doctor away!", "Count to ten , backwards",\
"Wake me up when you're finished.", "Better luck next time.",\
"It's getting late, hurry up!", "One more and we're finished...",\
"I'm running out of things to say.", "So close, yet so far!",\
"Nearly got it, maybe it's the next guess.")
if attempts==attempts >0:
print random.choice(WORDS)
print "----------------------------------------------------------------------"
print " "
if attempts == attempts > 13:
guess == number
import winsound
import time
time.sleep(1.5)
winsound.PlaySound("SystemExit", winsound.SND_ALIAS)
print " "
print "(The number was %i)" % (number)
print " "
print "***********************"
print "BETTER LUCK NEXT TIME."
print "***********************"
print " "
attempts=0
run = raw_input("\n'run' again or 'exit' ")
if run == "exit":
break
if guess == number:
print " "
print "********************************************"
print 'CONGRATULATIONS, YOU GUESSED IT IN %i TRIES!' % (attempts)
print "********************************************"
attempts=0
run = raw_input("\n'run' again or 'exit' ")
if run == "exit":
break
elif run == "run":
number = random.randint(1, 10000)
random.choice(WORDS)
continue
elif guess < number:
print 'NO, HIGHER THAN %d. (Turn No.%i of 13)' % (guess, attempts)
else:
print 'NO, LOWER THAN %d. (Turn No.%i of 13)' % (guess, attempts)
I've been working with Pyhton for about six months and have been wanting to put a program into a seperate Tkinter GUI but have had no luck.
I need to have a Tk GUI that has vertical scrolling exactly like the normal IDE except that positioned in the upper right corner will sit a tiny calculator.
This tiny calculator does not need to have the "x" or the "+" or the "-" etc or any of the other signs at all.
The reason is because the program is a simple high\low game and only needs to have the numbers from 0 to 9. The only other functions the calculator needs is the backspace (in case of mistakes) and an entry button to enter the number onto the left hand side of the page. Also a quit button to finish.
I have XP on my Compaq Evo desktop.
The program works fine except that when I try to put it into a different GUI all sorts of problems occur. Is this because I need to use pyw instead of py? Or do I just import it as is into the new GUI? I realize that "run==exit" will have to be replaced by quit or suchlike.
Thanks for any help (this is my first time on any forum).
import random
number = random.randint(1, 10000)
running = True
run=""
attempts=0
while running:
guess = int(raw_input('Enter an integer : '))
attempts = attempts + 1
WORDS=("Get it before ten tries or the world will explode!",\
"The next one is the 70th try, hurry!", "400 guesses later...",\
"A guess a day keeps the doctor away!", "Count to ten , backwards",\
"Wake me up when you're finished.", "Better luck next time.",\
"It's getting late, hurry up!", "One more and we're finished...",\
"I'm running out of things to say.", "So close, yet so far!",\
"Nearly got it, maybe it's the next guess.")
if attempts==attempts >0:
print random.choice(WORDS)
print "----------------------------------------------------------------------"
print " "
if attempts == attempts > 13:
guess == number
import winsound
import time
time.sleep(1.5)
winsound.PlaySound("SystemExit", winsound.SND_ALIAS)
print " "
print "(The number was %i)" % (number)
print " "
print "***********************"
print "BETTER LUCK NEXT TIME."
print "***********************"
print " "
attempts=0
run = raw_input("\n'run' again or 'exit' ")
if run == "exit":
break
if guess == number:
print " "
print "********************************************"
print 'CONGRATULATIONS, YOU GUESSED IT IN %i TRIES!' % (attempts)
print "********************************************"
attempts=0
run = raw_input("\n'run' again or 'exit' ")
if run == "exit":
break
elif run == "run":
number = random.randint(1, 10000)
random.choice(WORDS)
continue
elif guess < number:
print 'NO, HIGHER THAN %d. (Turn No.%i of 13)' % (guess, attempts)
else:
print 'NO, LOWER THAN %d. (Turn No.%i of 13)' % (guess, attempts)
•
•
Join Date: Feb 2007
Posts: 55
Reputation:
Solved Threads: 4
Thanks for your welcome Ene. I knew beforehand that I had to wrap the code somehow, but as this is not explained by an example or suchlike I was puzzled by how to do it. Be that as it may here's the code:
python Syntax (Toggle Plain Text)
import random number = random.randint(1, 10000) running = True run="" attempts=0 while running: guess = int(raw_input('Enter an integer : ')) attempts = attempts + 1 WORDS=("Get it before ten tries or the world will explode!",\ "The next one is the 70th try, hurry!", "400 guesses later...",\ "A guess a day keeps the doctor away!", "Count to ten , backwards",\ "Wake me up when you're finished.", "Better luck next time.",\ "It's getting late, hurry up!", "One more and we're finished...",\ "I'm running out of things to say.", "So close, yet so far!",\ "Nearly got it, maybe it's the next guess.") if attempts==attempts >0: print random.choice(WORDS) print "----------------------------------------------------------------------" print " " if attempts == attempts > 13: guess == number import winsound import time time.sleep(1.5) winsound.PlaySound("SystemExit", winsound.SND_ALIAS) print " " print "(The number was %i)" % (number) print " " print "***********************" print "BETTER LUCK NEXT TIME." print "***********************" print " " attempts=0 run = raw_input("\n'run' again or 'exit' ") if run == "exit": break if guess == number: print " " print "********************************************" print 'CONGRATULATIONS, YOU GUESSED IT IN %i TRIES!' % (attempts) print "********************************************" attempts=0 run = raw_input("\n'run' again or 'exit' ") if run == "exit": break elif run == "run": number = random.randint(1, 10000) random.choice(WORDS) continue elif guess < number: print 'NO, HIGHER THAN %d. (Turn No.%i of 13)' % (guess, attempts) else: print 'NO, LOWER THAN %d. (Turn No.%i of 13)' % (guess, attempts)[B][/B]
•
•
Join Date: Jul 2006
Posts: 608
Reputation:
Solved Threads: 150
I like the Windows shutdown sound when you lose. It threw me for half a second.
Here's a basic framework to get you started, and then a link to the manual that I use for Tkinter:
http://www.nmt.edu/tcc/help/pubs/tkinter/
http://www.nmt.edu/tcc/help/pubs/tkinter.pdf
Just as general pointers:
* You'll need to figure out how to disable the Text widget so the user can't type into it.
* You'll need to figure out how to bind the <Return> key to the Entry widget so that the user can hit Enter and get the appropriate obnoxious message from the program :lol:
* You'll probably want to configure the app differently so it looks better.
* You'll need to figure out how to supply callbacks to the Reset and Quit buttons.
Hope it helps, and post your final product!
Jeff
Here's a basic framework to get you started, and then a link to the manual that I use for Tkinter:
Python Syntax (Toggle Plain Text)
from Tkinter import * mainw = Tk() mainw.frame = Frame(mainw) mainw.frame.label = Label(mainw.frame,text="Guess a Number!") mainw.frame.label.grid(row=0,column=0) mainw.frame.entry = Entry(mainw.frame) mainw.frame.entry.grid(row=0,column=1,columnspan=2) mainw.frame.text = Text(mainw.frame,width=35,height=10) mainw.frame.text.grid(row=1,columnspan=2) mainw.frame.scroll = Scrollbar(mainw.frame,orient=VERTICAL, command=mainw.frame.text.yview) mainw.frame.text['yscrollcommand']=mainw.frame.scroll.set mainw.frame.scroll.grid(row=1,column=2,sticky=N+S) mainw.frame.rbutton = Button(mainw.frame,text="Restart") mainw.frame.rbutton.grid(row=2,column=0,sticky=E+W) mainw.frame.qbutton = Button(mainw.frame,text="Quit") mainw.frame.qbutton.grid(row=2,column=1,sticky=E+W) mainw.frame.grid() mainw.mainloop()
http://www.nmt.edu/tcc/help/pubs/tkinter/
http://www.nmt.edu/tcc/help/pubs/tkinter.pdf
Just as general pointers:
* You'll need to figure out how to disable the Text widget so the user can't type into it.
* You'll need to figure out how to bind the <Return> key to the Entry widget so that the user can hit Enter and get the appropriate obnoxious message from the program :lol:
* You'll probably want to configure the app differently so it looks better.
* You'll need to figure out how to supply callbacks to the Reset and Quit buttons.
Hope it helps, and post your final product!
Jeff
![]() |
Similar Threads
- Square root function in calculator (Java)
- Stuck in GUI (Python)
- Programming a gui in C (C++)
- calculator (Java)
- Calculator GUI (Java)
- How do you build the dot in calculator. (C++)
- Creating a GUI that accepts user input help (Java)
- Memory buttons problem (Java)
Other Threads in the Python Forum
- Previous Thread: Tiny Tkinter Calculator (Python)
- Next Thread: wxPython tutorials?
| Thread Tools | Search this Thread |
abrupt ansi anti apache approximation array assignment avogadro backend beginner binary bluetooth book builtin calculator character code converter countpasswordentry curved customdialog dan08 dictionaries dictionary dynamic examples exe file float format function gnu graphics gui heads homework ideas import inches input java launcher library line lines linux list lists loop mouse mysqlquery number numbers numeric output parsing path phonebook plugin pointer port prime programming progressbar projects py2exe pygame python random recursion redirect scrolledtext software statictext statistics string strings sum table terminal text textarea thread threading time tlapse trick tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable wordgame write wxpython xlib






