School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,146 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,725 people online right now. Registration is fast and FREE... Join Now!




trouble creating Gui WIndow using python/Tkinter

 

trouble creating Gui WIndow using python/Tkinter

jaziey

23 Sep, 2009 - 03:03 PM
Post #1

New D.I.C Head
*

Joined: 23 Sep, 2009
Posts: 6

Attached File  lazy2Buttons.txt ( 849bytes ) Number of downloads: 10
I am using Python for Absolute Beginners to create simple Gui windows and I am having trouble maintaining the window when there is an error. The screen quickly disappears. I am using windows XP and I am calling the .py script from the icon in start window instead of the IDE. I am using python 2.6. I have added the script to attachment and have commented out some lines to see if there are any improvements, but saw none.

thanks
jaziey

User is offlineProfile CardPM
+Quote Post


Dogstopper

RE: Trouble Creating Gui WIndow Using Python/Tkinter

23 Sep, 2009 - 03:27 PM
Post #2

The Epiphany
Group Icon

Joined: 15 Jul, 2008
Posts: 560



Thanked: 40 times
Dream Kudos: 675
My Contributions
You must indent everything inside the class by one, python sees it at an emty class.. as in, your function definitions need to be indented.

This post has been edited by Dogstopper: 23 Sep, 2009 - 03:28 PM
User is offlineProfile CardPM
+Quote Post

jaziey

RE: Trouble Creating Gui WIndow Using Python/Tkinter

23 Sep, 2009 - 10:21 PM
Post #3

New D.I.C Head
*

Joined: 23 Sep, 2009
Posts: 6

QUOTE(Dogstopper @ 23 Sep, 2009 - 03:27 PM) *

You must indent everything inside the class by one, python sees it at an emty class.. as in, your function definitions need to be indented.


Ok, I will correct that, but is there a way to keep the gui on the screen so I can see the problem. I know if it is a regular python script I can add " raw_input("\nPress Enter to Exit")"

thanks
Jaziey
User is offlineProfile CardPM
+Quote Post

jaziey

RE: Trouble Creating Gui WIndow Using Python/Tkinter

23 Sep, 2009 - 11:19 PM
Post #4

New D.I.C Head
*

Joined: 23 Sep, 2009
Posts: 6

QUOTE(jaziey @ 23 Sep, 2009 - 10:21 PM) *

QUOTE(Dogstopper @ 23 Sep, 2009 - 03:27 PM) *

You must indent everything inside the class by one, python sees it at an emty class.. as in, your function definitions need to be indented.


Ok, I will correct that, but is there a way to keep the gui on the screen so I can see the problem. I know if it is a regular python script I can add " raw_input("\nPress Enter to Exit")"

thanks
Jaziey



The gui code does not have any indentations. It does not use classes. It is a simple script:

from Tkinter import *

#create a root window

root = Tk()
root.title("Lazy Buttons")
root.geometry("200x85")

#create a frame in the window to hold other widgets

app = Frame(root)
app.grid()

# create a button in the frame
bttn1 = Button(app, text = "I do nothing!")
bttn1.grid()

#create a second button in the frame

bttn2 = Button(app)
bttn2.grid()

bttn2["text"] = "Me too!"

#bttn2.configure(test = "Me too!")

#create a third button in the frame

bttn3 = Button(app)
bttn3.grid()
bttn3["text"] = "Same here!"

#kick off the window's event loop

root.mainloop()
User is offlineProfile CardPM
+Quote Post

jaziey

RE: Trouble Creating Gui WIndow Using Python/Tkinter

23 Sep, 2009 - 11:32 PM
Post #5

New D.I.C Head
*

Joined: 23 Sep, 2009
Posts: 6

QUOTE(Dogstopper @ 23 Sep, 2009 - 03:27 PM) *

You must indent everything inside the class by one, python sees it at an emty class.. as in, your function definitions need to be indented.


OK that did work, the class was indented improperly, also if I run it in IDE, I see all my errors. I thought a Tkinter script was suppose to be executed froman icon instead of the IDE.
But IDE works fine.

thanks alot. smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 03:52PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month