| | |
Stuck in GUI
Thread Solved |
•
•
Join Date: Feb 2007
Posts: 55
Reputation:
Solved Threads: 4
G'day,
I've been googling for the last three weeks :eek: trying to get an example of a program larger than a simple "Hello World" that works inside it's own GUI.
I've been working on the "GUI with calculator" in this same section of Daniweb, but as soon as I put this program into a seperate GUI the main Idle GUI takes over and the other GUI disappears...
Thanks to everyone for their help so far...but what I really need to look at is a seperate working program that is longer than say twenty lines of code and has been put into a GUI of its own so that I can work out how to organize my own GUI. As I've said there seems to be no programs longer than a "Hello World" example to work with. I've only had about three weeks experience with the Tk code but most of the documentation is about building your own GUI but nothing is there about HOW to put a seperate working program into a GUI.
If someone could post an example/s of of how to do this I would be most grateful for their help.:lol:
"Ooie Gooie was a worm, a worm was Ooie Gooie. One day Ooie was lying on a train line when along came a train...OOOOOie GOOOOie!!!"
I've been googling for the last three weeks :eek: trying to get an example of a program larger than a simple "Hello World" that works inside it's own GUI.
I've been working on the "GUI with calculator" in this same section of Daniweb, but as soon as I put this program into a seperate GUI the main Idle GUI takes over and the other GUI disappears...
Thanks to everyone for their help so far...but what I really need to look at is a seperate working program that is longer than say twenty lines of code and has been put into a GUI of its own so that I can work out how to organize my own GUI. As I've said there seems to be no programs longer than a "Hello World" example to work with. I've only had about three weeks experience with the Tk code but most of the documentation is about building your own GUI but nothing is there about HOW to put a seperate working program into a GUI.
If someone could post an example/s of of how to do this I would be most grateful for their help.:lol:
"Ooie Gooie was a worm, a worm was Ooie Gooie. One day Ooie was lying on a train line when along came a train...OOOOOie GOOOOie!!!"
•
•
Join Date: Feb 2007
Posts: 55
Reputation:
Solved Threads: 4
G'day Jeff,
Below is one version of the code I have tried. I've tried about 20 different versions but can't seem to get it to work at all because the main Idle GUI keeps taking over.
Thanks for your reply.
Below is one version of the code I have tried. I've tried about 20 different versions but can't seem to get it to work at all because the main Idle GUI keeps taking over.
Python Syntax (Toggle Plain Text)
import random from Tkinter import * root = Tk() 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 " " answer1 = Button(root, text = 'NO, HIGHER THAN %d. (Turn No.%i of 13)', fg = 'red') answer1.grid() answer2 = Button(root, text = 'NO, HIGHER THAN %d. (Turn No.%i of 13)', fg = 'green') answer2.grid() 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
P.S. Jeff,
I have tried using you're example code in my program but it will not "take" at all. Maybe because they're working on two different threads as I'm sure that the "while" statement is interfering with the Tk GUI in some way...and I really don't know how to use "callbacks" etc. That's why I wanted to see other working codes that had been put into an independent GUI to see how they have worked their "callbacks" etc. Thanks again Jeff, if you're still unsure about what I'm trying to do please don't hesitate to post.
I have tried using you're example code in my program but it will not "take" at all. Maybe because they're working on two different threads as I'm sure that the "while" statement is interfering with the Tk GUI in some way...and I really don't know how to use "callbacks" etc. That's why I wanted to see other working codes that had been put into an independent GUI to see how they have worked their "callbacks" etc. Thanks again Jeff, if you're still unsure about what I'm trying to do please don't hesitate to post.
In a GUI print and input are replaced by label and entry components. Here is a typical example ...
python Syntax (Toggle Plain Text)
# a simple Tkinter number guessing game from Tkinter import * import random def click(): # get the number in the entry area num = int(enter1.get()) # check it out if num > rn: label3['text'] = 'Guessed too high! Enter another number!' elif num < rn: label3['text'] = 'Guessed too low! Enter another number!' else: label3['text'] = 'Guessed correctly!' # create the main/root window root = Tk() root.title() # pick a random integer from 1 to 10 rn = random.randrange(1, 11) # let the user know what is going on label1 = Label(root, text="Guess a number between 1 and 10") label1.grid(row=1, column=1, padx=8, pady=8) # prompt the user label2 = Label(root, text="Enter an integer number: ") label2.grid(row=2, column=1, padx=20, pady=8) # this your input area enter1 = Entry(root, width=5) enter1.grid(row=2, column=2, padx=8) enter1.focus() # this is your mouse action button, right-click it to execute command button1 = Button(root, text=" Press to check number ", command=click) button1.grid(row=3, column=1, pady=8) # the result displays here label3 = Label(root, text="", bg='yellow') label3.grid(row=4, column=1, columnspan=2, pady=8) # start the mouse/keyboard event loop root.mainloop()
May 'the Google' be with you!
![]() |
Similar Threads
- Positioning in GUI (Python)
- GUI development in LINUX (Window and Desktop Managers)
- Help with gui loop. (C)
Other Threads in the Python Forum
- Previous Thread: Multiple Tkinter windows/variables
- Next Thread: Python tuples and Sql query
| Thread Tools | Search this Thread |
abrupt ansi anti approximation assignment avogadro backend beginner binary bluetooth calculator character cmd code customdialog cx-freeze data decimals dictionaries dictionary directory dynamic error examples exe file float format function gnu graphics gui heads homework http ideas import input itunes java launcher leftmouse line linux list lists loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyglet pyqt python random recursion schedule screensaverloopinactive script scrolledtext sqlite ssh statistics string strings sudokusolver sum table terminal text thread threading time tlapse tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable ventrilo wikipedia write wxpython xlib






