Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old March 11th, 2004, 02:21 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonder.
Posts: 5,537 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Weeks 1 Day 21 h 42 m
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook
Tkinter button events

Im tring to to create this little practice program that ... when you click on OK button another button shows up but it does not seem to be working or i dont know how to do it right.. any ideas?

Code:
from Tkinter import *

class GUI:

      def __init__ (self, master):

          frame = Frame(master)
          frame.pack()

          self.label = Label(frame,{"text":"This is just a test program"})
          self.label.pack()

          self.button = Button(frame)
          self.button.configure(text="OK",background="blue",foreground="white",command=self.buttonClick(frame));
          self.button.pack(side=LEFT)


      def buttonClick(self,master):

          self.button1 = Button(master,text="Click")
          self.button1.pack(side=LEFT)




if __name__ == "__main__":

   root = Tk()
   root_gui = GUI(root)
   root.mainloop()

Reply With Quote
  #2  
Old March 11th, 2004, 03:33 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
You were close....
You have to give your Tkinter button a reference to the function that is to be called - so just it's name not the complete thing

In which case you need to track the main root window so you can hang buttons on it. The easiest way is to use an instance variable like self.master. This restriction is a major reason why most Tkinter programs are base around classes.

Code:
from Tkinter import*

class GUI: 

      def __init__(self, master): 

          self.master = master
          frame = Frame(self.master)
          frame.pack()

          self.label = Label(frame, {"text": "This is just a test program"})
          self.label.pack()

          self.button = Button(frame)
          self.button.configure(text = "OK", background = "blue", 
                foreground = "white", command = self.buttonClick); 
          self.button.pack(side = LEFT)


      def buttonClick(self): 

          self.button1 = Button(self.master, text = "Click")
          self.button1.pack(side = LEFT)




if __name__ == "__main__": 
   root = Tk()
   root_gui = GUI(root)
   root.mainloop()


Grim
__________________
*** Experimental Python Markup CGI V2 ***

Reply With Quote
  #3  
Old March 11th, 2004, 03:42 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
BTW out of interest, what text editor are you using? Your tabs are 3 chars and not 4. Not a problem if you only write your own stuff but it might get messy if you try pick-a-mix coding

Reply With Quote
  #4  
Old March 11th, 2004, 03:45 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonder.
Posts: 5,537 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108660 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Weeks 1 Day 21 h 42 m
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook
hehe nice.. good thing i was close for now on i will just something like.. what you did

Code:
self.master = master


im using context on windows.. do you have anything better? as im looking fro a better text editor.. btw how did you add them colors to your code tags

Reply With Quote
  #5  
Old March 11th, 2004, 05:18 PM
rebbit rebbit is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 84 rebbit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 7 m
Reputation Power: 5
you could also use a lambda function, if you want to avoid creating too many instance variables (though the root window is pretty much always one you will want to give your entire class access to).

Code:
Button(self, text="Test", command=lambda: self.somefunction(somevariable))

Reply With Quote
  #6  
Old March 11th, 2004, 05:57 PM
Boceifus's Avatar
Boceifus Boceifus is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 93 Boceifus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 59 m 57 sec
Reputation Power: 5
Code:
print 'I think he used his py2html'
print 'You can find it :'

Here
__________________
It is not important if the glass is half full or half empty.What is important,is who has been drinking from MY glass?!?!?

Reply With Quote
  #7  
Old March 11th, 2004, 06:25 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
You don't have to like my colours but if you use IDLE you might recognise them. PHP's built in colouriser is . I wanted something like it but that could generate more or less any markup. The GUI layout is a bit Mickey Mouse but I'm working on it, in fact I'm planning a complete re-work of most of the code

I prefer TextPad as an editor but I do use IDLE a lot.

Grim

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Tkinter button events


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway