From russblau at hotmail.com Thu Mar 2 22:14:54 2006 From: russblau at hotmail.com (Russell Blau) Date: Thu, 2 Mar 2006 16:14:54 -0500 Subject: [Tkinter-discuss] How to launch a dialog when app is started? Message-ID: I am trying to write a Tkinter application that will automatically display a particular dialog box on top of the application when it is initialized. (Like a word processor opening a "File Open" dialog as the first thing that happens when you enter the application.) How do I do this? I have a method that invokes the dialog box, but I cannot call it until after my app's mainloop has started; but once the mainloop has started, I can't call it from the program, either! I'm sure I'm overlooking something obvious here. Example (skeleton) code: from Tkinter import * class NewPageDialog(tkSimpleDialog.Dialog): def body(self, master, title="Select Target"): Label(master, text="Target page:").grid(row=0) self.targetpage = Entry(master) self.targetpage.grid(row=0, column=1) return self.targetpage def validate(self): return True def apply(self): pass class GuiApplication(Frame): def __init__(self, master): Frame.__init__(self, master) def newpage(self): n = NewPageDialog(self) self.targetpage = n.targetpage.get() if __name__ == "__main__": app = GuiApplication(Tk()) # do something here to cause GuiApplication to invoke newpage() method when it starts app.mainloop() From jepler at unpythonic.net Thu Mar 2 22:43:00 2006 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Thu, 2 Mar 2006 15:43:00 -0600 Subject: [Tkinter-discuss] How to launch a dialog when app is started? In-Reply-To: References: Message-ID: <20060302214300.GC16093@unpythonic.net> You might try writing app.after_idle(app.newpage) or simply: app = GuiApplication(Tk()) app.newpage() app.mainloop() except that this will always enter mainloop after newpage is called, which may not be what you desire. Jeff From harlinseritt at yahoo.com Fri Mar 3 13:53:04 2006 From: harlinseritt at yahoo.com (Harlin Seritt) Date: Fri, 3 Mar 2006 04:53:04 -0800 (PST) Subject: [Tkinter-discuss] How to launch a dialog when app is started? In-Reply-To: Message-ID: <20060303125304.55429.qmail@web52205.mail.yahoo.com> Hi Russell, This may be quite different but if I understand the requirements, you can try this: from Tkinter import * import tkFileDialog class app: def __init__(self, master): master.title('Hello') Button(master, text='Button').pack() tkFileDialog.askopenfilename() if __name__ == '__main__': root = Tk() app = app(root) root.mainloop() Harlin Seritt tkinter-discuss-request at python.org wrote: Send Tkinter-discuss mailing list submissions to tkinter-discuss at python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/tkinter-discuss or, via email, send a message with subject or body 'help' to tkinter-discuss-request at python.org You can reach the person managing the list at tkinter-discuss-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Tkinter-discuss digest..." Today's Topics: 1. How to launch a dialog when app is started? (Russell Blau) 2. Re: How to launch a dialog when app is started? (jepler at unpythonic.net) ---------------------------------------------------------------------- Message: 1 Date: Thu, 2 Mar 2006 16:14:54 -0500 From: "Russell Blau" Subject: [Tkinter-discuss] How to launch a dialog when app is started? To: tkinter-discuss at python.org Message-ID: I am trying to write a Tkinter application that will automatically display a particular dialog box on top of the application when it is initialized. (Like a word processor opening a "File Open" dialog as the first thing that happens when you enter the application.) How do I do this? I have a method that invokes the dialog box, but I cannot call it until after my app's mainloop has started; but once the mainloop has started, I can't call it from the program, either! I'm sure I'm overlooking something obvious here. Example (skeleton) code: from Tkinter import * class NewPageDialog(tkSimpleDialog.Dialog): def body(self, master, title="Select Target"): Label(master, text="Target page:").grid(row=0) self.targetpage = Entry(master) self.targetpage.grid(row=0, column=1) return self.targetpage def validate(self): return True def apply(self): pass class GuiApplication(Frame): def __init__(self, master): Frame.__init__(self, master) def newpage(self): n = NewPageDialog(self) self.targetpage = n.targetpage.get() if __name__ == "__main__": app = GuiApplication(Tk()) # do something here to cause GuiApplication to invoke newpage() method when it starts app.mainloop() ------------------------------ Message: 2 Date: Thu, 2 Mar 2006 15:43:00 -0600 From: jepler at unpythonic.net Subject: Re: [Tkinter-discuss] How to launch a dialog when app is started? To: Russell Blau Cc: tkinter-discuss at python.org Message-ID: <20060302214300.GC16093 at unpythonic.net> Content-Type: text/plain; charset=us-ascii You might try writing app.after_idle(app.newpage) or simply: app = GuiApplication(Tk()) app.newpage() app.mainloop() except that this will always enter mainloop after newpage is called, which may not be what you desire. Jeff ------------------------------ _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org http://mail.python.org/mailman/listinfo/tkinter-discuss End of Tkinter-discuss Digest, Vol 25, Issue 1 ********************************************** --------------------------------- Yahoo! Mail Bring photos to life! New PhotoMail makes sharing a breeze. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20060303/29975abc/attachment.htm From rkundu at ouray.cudenver.edu Fri Mar 3 18:57:40 2006 From: rkundu at ouray.cudenver.edu (rkundu at ouray.cudenver.edu) Date: Fri, 03 Mar 2006 10:57:40 -0700 Subject: [Tkinter-discuss] Accessing tables through Python (ActivePython 2.3) Message-ID: <20060303105740.01t6epu1w448o4wo@maroon.cudenver.edu> I am trying to read the field names from a dbf table using python. Is there any way to do this? I tried using PyTables and also PyIMAPITable but no luck. I also tried sending a dispatch "DAO.DBEngine", but failed. Any suggestions will be appreciated. Thank you, Reema From haofast2006 at hotmail.com Tue Mar 7 15:35:07 2006 From: haofast2006 at hotmail.com (V H) Date: Tue, 07 Mar 2006 14:35:07 +0000 Subject: [Tkinter-discuss] question on scalable frame Message-ID: Hello, I am using Tkinter to create a scalable/expandable frame and using pack() to manage it. On the frame there are several dynamically created sub-frames. The top level frame is expanded automatically with the increasing number of sub-frames. But after I adjust the size of the top-level frame using mouse, it cannot expand automatically. Is it normal? Or how can I resolve it? Thanks. regards, Weining _________________________________________________________________ Don't just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/ From mfranklin1 at gatwick.westerngeco.slb.com Tue Mar 7 15:40:50 2006 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue, 07 Mar 2006 14:40:50 +0000 Subject: [Tkinter-discuss] question on scalable frame In-Reply-To: References: Message-ID: <440D9B72.4080303@gatwick.westerngeco.slb.com> V H wrote: > Hello, > > I am using Tkinter to create a scalable/expandable frame and using pack() to > manage it. On the frame there are several dynamically created sub-frames. > The top level frame is expanded automatically with the increasing number of > sub-frames. But after I adjust the size of the top-level frame using mouse, > it cannot expand automatically. Is it normal? Or how can I resolve it? > Thanks. > > regards, > Weining > Hi, Could you post some code that show this... perhaps it is as simple as the pack expand or fill option.. CHeers Martin From jepler at unpythonic.net Tue Mar 7 17:24:06 2006 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Tue, 7 Mar 2006 10:24:06 -0600 Subject: [Tkinter-discuss] question on scalable frame In-Reply-To: References: Message-ID: <20060307162406.GC7188@unpythonic.net> Once the user has adjusted the size of the window, many window managers keep the window at the user-requested size, rather than the application-requested size. By setting an empty geometry when resizing the window, this behavior can be avoided, at least on my system. e.g., in python, app.wm_geometry("") Here's a wish program that demonstrates the solution (and the problem, if the "wm geo" section is commented out): #------------------------------------------------------------------------ label .l -width 10 -bg red button .b -text "<<" -command {width -1} button .b1 -text ">>" -command {width 1} proc width arg { set w [.l cget -width] incr w $arg if {$w < 0} { set $w 0 } .l configure -width $w # Reset window to use application, not user, size # Comment this out to show the problem or do something more sophisticated # (like check if the new requested size is greater than the current size, so # as to grow but not shrink) wm geometry . {} } pack .l -side top pack .b -side left pack .b1 -side left #------------------------------------------------------------------------ Jeff From hk at pop.ms Wed Mar 15 03:20:05 2006 From: hk at pop.ms (hk at pop.ms) Date: Wed, 15 Mar 2006 03:20:05 +0100 Subject: [Tkinter-discuss] Tix: binding Message-ID: <382176391@web.de> I am looking at Tix and I am stuck with what seems to be a simple problem: I want to bind the cancel buttom of a ExFileSelectBox to a routine in my class, but can not make it work. I guess the problem is the same for any binding of tix sub-widgets, so if someone could send some sample code. >>> import Tix >>> root = Tix.Tk() >>> box = Tix.ExFileSelectBox(root) >>> print box.subwidget(name='cancel') .11827520.bf.cancel #so the sub-widget cancel buttom is there But how to bind it ? >>> box.cancel(command = lambda a,b : a+b ) Traceback (most recent call last): File "", line 1, in ? box.cancel(command = lambda a,b : a+b ) AttributeError: _dummyButton instance has no __call__ method Or >>> box.subwidget(name='cancel' , command = lambda a,b : a+b ) Traceback (most recent call last): File "", line 1, in ? box.subwidget(name='cancel' , command = lambda a,b : a+b ) TypeError: subwidget() got an unexpected keyword argument 'command' So, it seems I can not bind to command, but what then ? >From the Tix docu I thought the buttoms are normal Tkinter widgets ? -- Harm From m_tayseer82 at yahoo.com Wed Mar 15 10:37:21 2006 From: m_tayseer82 at yahoo.com (Mohammad Tayseer) Date: Wed, 15 Mar 2006 01:37:21 -0800 (PST) Subject: [Tkinter-discuss] Tix: binding In-Reply-To: <382176391@web.de> Message-ID: <20060315093721.84407.qmail@web31107.mail.mud.yahoo.com> > >>> box.cancel(command = lambda a,b : a+b ) > Traceback (most recent call last): > File " ", line 1, in ? > box.cancel(command = lambda a,b : a+b ) > AttributeError: _dummyButton instance has no __call__ method you should use box.cancel.config(command=my_callback) AFAIK --------------------------------- Yahoo! Mail Use Photomail to share photos without annoying attachments. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20060315/3b5eb547/attachment.htm From adam.jtm30 at gmail.com Wed Mar 15 18:36:24 2006 From: adam.jtm30 at gmail.com (Adam) Date: Wed, 15 Mar 2006 17:36:24 +0000 Subject: [Tkinter-discuss] [Tutor] Tix: binding In-Reply-To: <382176391@web.de> References: <382176391@web.de> Message-ID: On 15/03/06, hk at pop.ms wrote: > I am looking at Tix and I am stuck with what seems to be a simple problem: > > I want to bind the cancel buttom of a ExFileSelectBox to a routine in my class, but can not make it work. > I guess the problem is the same for any binding of tix sub-widgets, so if someone could send some sample code. > >>> import Tix > >>> root = Tix.Tk() > >>> box = Tix.ExFileSelectBox(root) > >>> print box.subwidget(name='cancel') > .11827520.bf.cancel #so the sub-widget cancel buttom is there > > But how to bind it ? > > >>> box.cancel(command = lambda a,b : a+b ) > Traceback (most recent call last): > File "", line 1, in ? > box.cancel(command = lambda a,b : a+b ) > AttributeError: _dummyButton instance has no __call__ method > > Or > > >>> box.subwidget(name='cancel' , command = lambda a,b : a+b ) > Traceback (most recent call last): > File "", line 1, in ? > box.subwidget(name='cancel' , command = lambda a,b : a+b ) > TypeError: subwidget() got an unexpected keyword argument 'command' > > So, it seems I can not bind to command, but what then ? > >From the Tix docu I thought the buttoms are normal Tkinter widgets ? > -- > Harm Here's what I got from a little experimentation and print box.cancel.bind.__doc__. >>> def bar(action): ... print action >>> import Tix >>> root = Tix.Tk() >>> box = Tix.ExFileSelectBox(root) >>> box.pack() >>> box.cancel.bind("", bar) '-1212073588bar' >>> If you have a look at box.cancel.bind.__doc__ you can find everything you can put into the SEQUENCE string "" is left mouse click. From haofast2006 at hotmail.com Fri Mar 17 17:40:06 2006 From: haofast2006 at hotmail.com (V H) Date: Fri, 17 Mar 2006 16:40:06 +0000 Subject: [Tkinter-discuss] question on displaying inserted text in widget 'Text' Message-ID: Hello, The function what I implemented takes 30 seconds. Before running it I want to give some message to user by displaying them in the widget 'Text'. Seems it's not useful because the message are always displayed after the excution. Could you help me to resolve it? Thanks a lot. best regards, Weining The sample file is as following: from Tkinter import * import time class one: def __init__(self, master): self.text=None frame = Frame(master) button = Button(tk,text='start', command=self.execute) button.pack() self.text = Text(frame,width=30,height=10) self.text.pack() frame.pack() def addMessage(self,message): self.text.insert(END,self.getCurrentTime()) self.text.insert(END,message) self.text.insert(END, '\n') def getCurrentTime(self): now = time.localtime(time.time()) year, month, day, hour, minute, second, weekday, yearday, daylight = now return "%02d:%02d:%02d" % (hour, minute, second) def execute(self): self.addMessage(' Start testing') for i in range(10000): for j in range (2000): i*j self.addMessage(' Finish testing') tk = Tk() o = one(tk) tk.mainloop() _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ From fredrik at pythonware.com Fri Mar 17 18:02:16 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 17 Mar 2006 18:02:16 +0100 Subject: [Tkinter-discuss] question on displaying inserted text in widget'Text' References: Message-ID: "V H" wrote: > The function what I implemented takes 30 seconds. Before running it I want > to give some message to user by displaying them in the widget 'Text'. Seems > it's not useful because the message are always displayed after the excution. > Could you help me to resolve it? call self.text.update_idletasks() or self.text.update() after you've modified the contents, but before you enter the test loop. it's probably easiest to add it to the addMessage method: def addMessage(self,message): self.text.insert(END,self.getCurrentTime()) self.text.insert(END,message) self.text.insert(END, '\n') self.text.update_idletasks() # <-- force update From stewart.midwinter at gmail.com Fri Mar 17 18:11:37 2006 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Fri, 17 Mar 2006 10:11:37 -0700 Subject: [Tkinter-discuss] question on displaying inserted text in widget 'Text' In-Reply-To: References: Message-ID: one line is all you need to change. def execute(self): self.addMessage(' Start testing') tk.update() for i in range(10000): for j in range (2000): i*j self.addMessage(' Finish testing') BTW, it's customary, though certainly not necessary, to call your main window 'root' (you used 'tk'). cheers, On 3/17/06, V H wrote: > Hello, > > The function what I implemented takes 30 seconds. Before running it I want > to give some message to user by displaying them in the widget 'Text'. Seems > it's not useful because the message are always displayed after the excution. > Could you help me to resolve it? Thanks a lot. -- Stewart Midwinter stewart at midwinter.ca stewart.midwinter at gmail.com Skype, GoogleTalk, iChatAV, MSN, Yahoo: midtoad AIM:midtoad1 From stewart.midwinter at gmail.com Fri Mar 17 18:13:01 2006 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Fri, 17 Mar 2006 10:13:01 -0700 Subject: [Tkinter-discuss] question on displaying inserted text in widget'Text' In-Reply-To: References: Message-ID: Man you've got to be fast to get ahead of Fredrik! And his solution is better than mine, anyway... :-) S From rowen at cesmail.net Fri Mar 17 19:54:56 2006 From: rowen at cesmail.net (Russell E. Owen) Date: Fri, 17 Mar 2006 10:54:56 -0800 Subject: [Tkinter-discuss] Trouble quitting a Tkinter app on Windows Message-ID: I have a Python/Tkinter application that runs on various platforms. When the user selects "quit", I call root.quit() or sys.exit(0) (newer vs. older version of the code). This works on all platforms except Windows. On Windows when the user quits (which calls quit on the root toplevel), it always exits with the following error dialog: This application has requested the Runtime to terminate it in an unusual way. Please contact the application"s support team for more information. A google search shows that others have had this problem -- especially PMW users -- but nobody seems to understand why. I posted to the tk newsgroup and was told that tk users don't see this problem, so it may be a Tkinter bug. One user suggested calling root.destroy() first. That does work but it takes a surprisingly long time as each toplevel in turn is destroyed. (It is nearly instantaneous on other platforms, but also unnecessary). My application (a telescope control GUI) has many toplevels, uses tkFont objects to manage display fonts and has a few background tasks (that use "after"). I don't know if any of these are relevant, but I certainly get the feeling that simpler applications don't show the problem. Any ideas? Should I file a Tkinter bug report? -- Russell From Cameron at phaseit.net Fri Mar 17 20:05:00 2006 From: Cameron at phaseit.net (Cameron Laird) Date: Fri, 17 Mar 2006 19:05:00 +0000 Subject: [Tkinter-discuss] Trouble quitting a Tkinter app on Windows In-Reply-To: References: Message-ID: <20060317190500.GA20868@lairds.us> On Fri, Mar 17, 2006 at 10:54:56AM -0800, Russell E. Owen wrote: . . . > I have a Python/Tkinter application that runs on various platforms. When > the user selects "quit", I call root.quit() or sys.exit(0) (newer vs. > older version of the code). This works on all platforms except Windows. > > On Windows when the user quits (which calls quit on the root toplevel), > it always exits with the following error > dialog: > > This application has requested the Runtime to terminate it in an unusual > way. > Please contact the application"s support team for more information. > > A google search shows that others have had this problem -- especially > PMW users -- but nobody seems to understand why. I posted to the tk > newsgroup and was told that tk users don't see this problem, so it may > be a Tkinter bug. > > One user suggested calling root.destroy() first. That does work but it > takes a surprisingly long time as each toplevel in turn is destroyed. > (It is nearly instantaneous on other platforms, but also unnecessary). > > My application (a telescope control GUI) has many toplevels, uses tkFont > objects to manage display fonts and has a few background tasks (that use > "after"). I don't know if any of these are relevant, but I certainly get > the feeling that simpler applications don't show the problem. > > Any ideas? Should I file a Tkinter bug report? . . . 1. Telescope control--'sounds neat. When'll it show up in Conference proceedings? 2. I think it deserves a fault report. Can you isolate it more? That is, I don't see the symptom with the simplest possible Tkinter programs, under Windows, but you do, so how do we identify what's different about your application? From stewart.midwinter at gmail.com Fri Mar 17 22:21:18 2006 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Fri, 17 Mar 2006 14:21:18 -0700 Subject: [Tkinter-discuss] Trouble quitting a Tkinter app on Windows In-Reply-To: References: Message-ID: I've had that same error message using Pmw widgets. Yes, I use root.destroy(), and no, I don't have the problem any more. def end(self): '''# Quit Scenario Manager Application''' try: root.destroy() except TclError: #exception occurs if busyBar is active when we quit pass if self.debug: print "ran root.destroy" sys.exit(0) S On 3/17/06, Russell E. Owen wrote: > > This application has requested the Runtime to terminate it in an unusual > way. cheers -- Stewart Midwinter stewart at midwinter.ca stewart.midwinter at gmail.com Skype, GoogleTalk, iChatAV, MSN, Yahoo: midtoad AIM:midtoad1 From mannslists at invigorated.org Mon Mar 20 19:10:41 2006 From: mannslists at invigorated.org (Mannequin*) Date: Mon, 20 Mar 2006 12:10:41 -0600 Subject: [Tkinter-discuss] Need help with a text + scrollbar widget and expansion Message-ID: <441EF021.2010101@invigorated.org> Hi all, I'm new to the list, and I have a question about how I can get a text + scrollbar widget to expand properly in their frame. I'll first give you the sample code, then I'll link to images of the problem. ********************************************************************* from Tkinter import * APP_NAME = "Spurgeon" APP_VERSION = "0.10" BIBLE_BOOKS = ["Genesis", "Exodus", "Leviticus", "Numbers"] class Spurgeon (Frame): """Hopefully a class to create the Tkinter interface""" def __init__ (self, parent = None): """Creates main window and widgets""" self.root = Tk () self.root.title (APP_NAME + ' ' + APP_VERSION) self.root.config (borderwidth = 3) Frame.__init__ (self, parent) self.pack (fill = "both", expand = "yes") self.make_widgets () def make_widgets (self): """Create the widgets for the main window""" # Create the main menu self.mainmenu = Menu (self.root) # Create the File menu self.file_menu = Menu (self.mainmenu, tearoff = 0) self.file_menu.add_command (label = "Open", underline = 0) self.file_menu.add_separator () self.file_menu.add_command (label = "Quit", underline = 0, command = self.root.quit) self.mainmenu.add_cascade (label = "File", menu = self.file_menu, underline = 0) # Create the Edit menu self.edit_menu = Menu (self.mainmenu, tearoff = 0) self.edit_menu.add_command (label = "Cut", underline = 2) self.edit_menu.add_command (label = "Copy", underline = 0) self.edit_menu.add_command (label = "Paste", underline = 0) self.edit_menu.add_command (label = "Delete", underline = 0) self.mainmenu.add_cascade (label = "Edit", menu = self.edit_menu, underline = 0) # Create the Help menu self.help_menu = Menu (self.mainmenu, tearoff = 0) self.help_menu.add_command (label = "About", underline = 0) self.mainmenu.add_cascade (label = "Help", menu = self.help_menu, underline = 0) # Display the main menu self.root.config (menu = self.mainmenu) # Create the left frame self.tool_frame = Frame (self, borderwidth = 2) self.tool_frame.pack (side = LEFT, anchor = NW) Label (self.tool_frame, text = "Left frame").pack () # Create the right frame self.view_frame = Frame (self, borderwidth = 2) self.view_frame.pack (side = RIGHT, expand = "yes", fill = "both") # Create the area where the Bible is viewed from self.bible_scroll = Scrollbar (self.view_frame) self.bible_view = Text (self.view_frame, relief = SUNKEN) self.bible_scroll.config (command = self.bible_view.yview) self.bible_view.config (yscrollcommand = self.bible_scroll.set) self.bible_view.pack (side = LEFT, fill = "both", expand = "yes") self.bible_scroll.pack (side = RIGHT, fill = Y, expand = "yes", anchor = W) if (__name__ == "__main__"): a = Spurgeon () a.mainloop () ********************************************************************* Now, if you run this, you'll notice that when you expand the window horizontally ( <---> ) that the text + scrollbar widget doesn't expand with the window. Here is a screenshot of the problem to illustrate what I'm talking about: I hope I've given enough information here to be helpful. By the way, is there anyway to enhance the look of the Tkinter widgets under Linux using what comes standard with Python. I'm trying to stay as standard as I possibly can. Thanks! -M. From klappnase at web.de Tue Mar 21 12:18:34 2006 From: klappnase at web.de (Michael Lange) Date: Tue, 21 Mar 2006 12:18:34 +0100 Subject: [Tkinter-discuss] Need help with a text + scrollbar widget and expansion In-Reply-To: <441EF021.2010101@invigorated.org> References: <441EF021.2010101@invigorated.org> Message-ID: <20060321121834.47192c5b.klappnase@web.de> On Mon, 20 Mar 2006 12:10:41 -0600 Mannequin* wrote: > Now, if you run this, you'll notice that when you expand the window > horizontally ( <---> ) that the text + scrollbar widget doesn't expand > with the window. > > self.bible_scroll.pack (side = RIGHT, fill = Y, expand = "yes", anchor = W) Remove the expand='yes' from the line above. > > By the way, is there anyway to enhance the look of the Tkinter widgets > under Linux using what comes standard with Python. I'm trying to stay as > standard as I possibly can. > You can change some of Tk's "ugly" defaults in an option database, that may look something like this: *font : Helvetica -12 *Entry*background : white *Listbox*background : white *Listbox*exportSelection : 0 *selectBackground : blue4 *selectForeground : white *Scrollbar*takeFocus : 0 *Scrollbar*highlightThickness : 0 *Menu*tearOff : 0 etc. If you store this in a file "optionDB" you can apply the new defaults with: root = Tk() root.option_readfile() I hope this helps Michael From harlinseritt at yahoo.com Tue Mar 21 12:48:12 2006 From: harlinseritt at yahoo.com (Harlin Seritt) Date: Tue, 21 Mar 2006 03:48:12 -0800 (PST) Subject: [Tkinter-discuss] Tkinter-discuss Digest, Vol 25, Issue 7 In-Reply-To: Message-ID: <20060321114812.81188.qmail@web52215.mail.yahoo.com> Hi Mr. M.- Change this line: self.bible_scroll.pack (side = RIGHT, fill = Y, expand = "yes", anchor = W) to this: self.bible_scroll.pack (side = RIGHT, fill = Y, anchor = W) Remember that not everything needs to expand! Good luck with your project! If you get a chance, I'd like to know more offline (away from this list) about your app. Thanks, Harlin Seritt http://www.seritt.org tkinter-discuss-request at python.org wrote: Send Tkinter-discuss mailing list submissions to tkinter-discuss at python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/tkinter-discuss or, via email, send a message with subject or body 'help' to tkinter-discuss-request at python.org You can reach the person managing the list at tkinter-discuss-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Tkinter-discuss digest..." Today's Topics: 1. Need help with a text + scrollbar widget and expansion (Mannequin*) ---------------------------------------------------------------------- Message: 1 Date: Mon, 20 Mar 2006 12:10:41 -0600 From: Mannequin* Subject: [Tkinter-discuss] Need help with a text + scrollbar widget and expansion To: Tkinter Discuss Message-ID: <441EF021.2010101 at invigorated.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hi all, I'm new to the list, and I have a question about how I can get a text + scrollbar widget to expand properly in their frame. I'll first give you the sample code, then I'll link to images of the problem. ********************************************************************* from Tkinter import * APP_NAME = "Spurgeon" APP_VERSION = "0.10" BIBLE_BOOKS = ["Genesis", "Exodus", "Leviticus", "Numbers"] class Spurgeon (Frame): """Hopefully a class to create the Tkinter interface""" def __init__ (self, parent = None): """Creates main window and widgets""" self.root = Tk () self.root.title (APP_NAME + ' ' + APP_VERSION) self.root.config (borderwidth = 3) Frame.__init__ (self, parent) self.pack (fill = "both", expand = "yes") self.make_widgets () def make_widgets (self): """Create the widgets for the main window""" # Create the main menu self.mainmenu = Menu (self.root) # Create the File menu self.file_menu = Menu (self.mainmenu, tearoff = 0) self.file_menu.add_command (label = "Open", underline = 0) self.file_menu.add_separator () self.file_menu.add_command (label = "Quit", underline = 0, command = self.root.quit) self.mainmenu.add_cascade (label = "File", menu = self.file_menu, underline = 0) # Create the Edit menu self.edit_menu = Menu (self.mainmenu, tearoff = 0) self.edit_menu.add_command (label = "Cut", underline = 2) self.edit_menu.add_command (label = "Copy", underline = 0) self.edit_menu.add_command (label = "Paste", underline = 0) self.edit_menu.add_command (label = "Delete", underline = 0) self.mainmenu.add_cascade (label = "Edit", menu = self.edit_menu, underline = 0) # Create the Help menu self.help_menu = Menu (self.mainmenu, tearoff = 0) self.help_menu.add_command (label = "About", underline = 0) self.mainmenu.add_cascade (label = "Help", menu = self.help_menu, underline = 0) # Display the main menu self.root.config (menu = self.mainmenu) # Create the left frame self.tool_frame = Frame (self, borderwidth = 2) self.tool_frame.pack (side = LEFT, anchor = NW) Label (self.tool_frame, text = "Left frame").pack () # Create the right frame self.view_frame = Frame (self, borderwidth = 2) self.view_frame.pack (side = RIGHT, expand = "yes", fill = "both") # Create the area where the Bible is viewed from self.bible_scroll = Scrollbar (self.view_frame) self.bible_view = Text (self.view_frame, relief = SUNKEN) self.bible_scroll.config (command = self.bible_view.yview) self.bible_view.config (yscrollcommand = self.bible_scroll.set) self.bible_view.pack (side = LEFT, fill = "both", expand = "yes") self.bible_scroll.pack (side = RIGHT, fill = Y, expand = "yes", anchor = W) if (__name__ == "__main__"): a = Spurgeon () a.mainloop () ********************************************************************* Now, if you run this, you'll notice that when you expand the window horizontally ( <---> ) that the text + scrollbar widget doesn't expand with the window. Here is a screenshot of the problem to illustrate what I'm talking about: I hope I've given enough information here to be helpful. By the way, is there anyway to enhance the look of the Tkinter widgets under Linux using what comes standard with Python. I'm trying to stay as standard as I possibly can. Thanks! -M. ------------------------------ _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org http://mail.python.org/mailman/listinfo/tkinter-discuss End of Tkinter-discuss Digest, Vol 25, Issue 7 ********************************************** --------------------------------- Yahoo! Mail Bring photos to life! New PhotoMail makes sharing a breeze. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20060321/b0e5e000/attachment.html From mannslists at invigorated.org Wed Mar 22 03:23:26 2006 From: mannslists at invigorated.org (Mannequin*) Date: Tue, 21 Mar 2006 20:23:26 -0600 Subject: [Tkinter-discuss] Need help with a text + scrollbar widget and expansion In-Reply-To: <20060321121834.47192c5b.klappnase@web.de> References: <441EF021.2010101@invigorated.org> <20060321121834.47192c5b.klappnase@web.de> Message-ID: <4420B51E.20509@invigorated.org> Michael Lange wrote: > On Mon, 20 Mar 2006 12:10:41 -0600 Mannequin* > wrote: > >> Now, if you run this, you'll notice that when you expand the window >> horizontally ( <---> ) that the text + scrollbar widget doesn't >> expand with the window. >> >> self.bible_scroll.pack (side = RIGHT, fill = Y, expand = "yes", >> anchor = W) > > Remove the expand='yes' from the line above. Ah, thank you. This did exactly what I wanted. :) I think I had this working at one point before the electricity went out and I didn't have my laptop battery in. D'OH! >> By the way, is there anyway to enhance the look of the Tkinter >> widgets under Linux using what comes standard with Python. I'm >> trying to stay as standard as I possibly can. >> > You can change some of Tk's "ugly" defaults in an option database, > that may look something like this: ... > etc. > > If you store this in a file "optionDB" you can apply the new defaults > with: > > root = Tk() root.option_readfile() > > I hope this helps It does a lot. Thank you. While I was looking around the unpythonic wiki, I ran into a something that someone using Tcl/Tk wrote to make it look more like GTK+ 1.2.x. Once I applied those, it helped it look a bit more 'modern' for my tastes. Thanks again! -M. From geon at post.cz Sun Mar 26 22:01:17 2006 From: geon at post.cz (geon) Date: Sun, 26 Mar 2006 22:01:17 +0200 Subject: [Tkinter-discuss] tag_bind Message-ID: <4426F30D.2040403@post.cz> Hi, On a canvas I would like to bind my "player" with arrows keys, but must be there something wrong, cause it is not able to bind it. This is my code: from Tkinter import * def move(what): print what.keycode master=Tk() myCanvas=Canvas(master, bg="white") pos=(20,20,30,30) player=myCanvas.create_oval(pos, fill="blue") myCanvas.focus(player) myCanvas.tag_bind(player, "", move) myCanvas.pack() mainloop() Thank you for your help. -- geon volume doprava. From klappnase at web.de Mon Mar 27 11:50:00 2006 From: klappnase at web.de (Michael Lange) Date: Mon, 27 Mar 2006 11:50:00 +0200 Subject: [Tkinter-discuss] tag_bind In-Reply-To: <4426F30D.2040403@post.cz> References: <4426F30D.2040403@post.cz> Message-ID: <20060327115000.5766989c.klappnase@web.de> On Sun, 26 Mar 2006 22:01:17 +0200 geon wrote: > Hi, > > On a canvas I would like to bind my "player" with arrows keys, but must > be there something wrong, cause it is not able to bind it. This is my code: > > from Tkinter import * > > def move(what): > print what.keycode > > > master=Tk() > myCanvas=Canvas(master, bg="white") > pos=(20,20,30,30) > player=myCanvas.create_oval(pos, fill="blue") > > myCanvas.focus(player) > myCanvas.tag_bind(player, "", move) > myCanvas.pack() > > mainloop() > Hi Geon, I don't think you can pass keyboard focus to canvas items this way, you will have to bind to the Canvas widget itself. Michael From geon at post.cz Mon Mar 27 18:54:05 2006 From: geon at post.cz (Pavel Kosina) Date: Mon, 27 Mar 2006 18:54:05 +0200 Subject: [Tkinter-discuss] tag_bind In-Reply-To: <20060327115000.5766989c.klappnase@web.de> References: <4426F30D.2040403@post.cz> <20060327115000.5766989c.klappnase@web.de> Message-ID: <442818AD.3010208@post.cz> Michael Lange napsal(a): > > Hi Geon, > > I don't think you can pass keyboard focus to canvas items this way, you will have to bind > to the Canvas widget itself. > > In fact, I tried this too, but the same effect. I got the impression from the documentation that this should be the right method. With binding canvas I do not know, how to bind more than one player, so that each one could be moved separately. Thank you Pavel Kosina (geon) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20060327/37e03e5e/attachment.html From klappnase at web.de Tue Mar 28 13:12:09 2006 From: klappnase at web.de (Michael Lange) Date: Tue, 28 Mar 2006 13:12:09 +0200 Subject: [Tkinter-discuss] tag_bind In-Reply-To: <442818AD.3010208@post.cz> References: <4426F30D.2040403@post.cz> <20060327115000.5766989c.klappnase@web.de> <442818AD.3010208@post.cz> Message-ID: <20060328131209.549aaaac.klappnase@web.de> On Mon, 27 Mar 2006 18:54:05 +0200 Pavel Kosina wrote: > > > In fact, I tried this too, but the same effect. I got the impression > from the documentation that this should be the right method. With > binding canvas I do not know, how to bind more than one player, so that > each one could be moved separately. > > Hi Pavel, maybe you could use Canvases as Players. Just for fun I wrote a little "Player" class that seems to do what you want: from Tkinter import * class Player(Canvas): def __init__(self, master, x, y): Canvas.__init__(self, master, width=12, height=12, bg='white', bd=0, highlightthickness=0, takefocus=1) self.master = master self.x = x self.y = y self.tag = master.create_window(x, y, window=self) self.oval = self.create_oval(0, 0, 10, 10, fill='blue') self.bind('', self._on_focus_in) self.bind('', self._on_focus_out) for key in ('', '', '', ''): self.bind(key, self.move) def _on_focus_in(self, event): self.itemconfigure(self.oval, fill='red') def _on_focus_out(self, event): self.itemconfigure(self.oval, fill='blue') def coords(self, x=None, y=None): if x == None: x = self.x if y == None: y = self._y self.x, self.y = x, y self.master.coords(self.tag, x, y) return x, y def move(self, event): x, y = self.x, self.y k = event.keysym if k == 'Up': y -= 1 elif k == 'Down': y += 1 elif k == 'Left': x -= 1 elif k == 'Right': x += 1 self.coords(x, y) ############################################## # test master=Tk() myCanvas=Canvas(master, bg="white") player1 = Player(myCanvas, 20, 20) player2 = Player(myCanvas, 50, 50) myCanvas.pack() player1.focus_set() mainloop() From geon at post.cz Tue Mar 28 20:54:22 2006 From: geon at post.cz (Pavel Kosina) Date: Tue, 28 Mar 2006 20:54:22 +0200 Subject: [Tkinter-discuss] tag_bind In-Reply-To: <20060328131209.549aaaac.klappnase@web.de> References: <4426F30D.2040403@post.cz> <20060327115000.5766989c.klappnase@web.de> <442818AD.3010208@post.cz> <20060328131209.549aaaac.klappnase@web.de> Message-ID: <4429865E.7080107@post.cz> Michael Lange napsal(a): >> In fact, I tried this too, but the same effect. I got the impression >> from the documentation that this should be the right method. With >> binding canvas I do not know, how to bind more than one player, so that >> each one could be moved separately. >> >> >> > > Hi Pavel, > > maybe you could use Canvases as Players. Just for fun I wrote a little "Player" class that > seems to do what you want: > So in other words you would like to tell me that funcionality of tag_bind is broken? That it is not working in this version? Your solution is nice, thank you for that, but I would like to stand on most simple solution, standard one, because of teaching reasons. I am a leader of a small group of teenager pythonniers, and this is another step I would like to go to.... Thank you all of you for help so far. Pavel Kosina (geon) -- Pavel Kosina ICQ 176015287 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20060328/8bbe6b8c/attachment.html From fredrik at pythonware.com Tue Mar 28 22:19:31 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 28 Mar 2006 22:19:31 +0200 Subject: [Tkinter-discuss] tag_bind References: <4426F30D.2040403@post.cz> <20060327115000.5766989c.klappnase@web.de> <442818AD.3010208@post.cz><20060328131209.549aaaac.klappnase@web.de> <4429865E.7080107@post.cz> Message-ID: Pavel Kosina wrote: > So in other words you would like to tell me that funcionality of > tag_bind is broken? That it is not working in this version? keyboard events are always sent to the item that has focus, and you can only set focus to items that support the insertion cursor protocol. in stock tk/tkinter, "text" is the only item type that supports that protocol. # # working keyboard tag_bind example from Tkinter import * def move(what): print what.keycode myCanvas=Canvas(bg="white") player=myCanvas.create_text((20, 20), text="hello", fill="blue") myCanvas.focus(player) myCanvas.focus_set() # <-- canvas must have focus myCanvas.tag_bind(player, "", move) myCanvas.pack() mainloop() From gerardo at computo-industrial.com.mx Tue Mar 28 23:09:36 2006 From: gerardo at computo-industrial.com.mx (Gerardo Juarez) Date: Tue, 28 Mar 2006 16:09:36 -0500 (EST) Subject: [Tkinter-discuss] Tix question [possibly off-topic] In-Reply-To: Message-ID: Hi, I need widgets which are a bit more elaborated than what Tk offers as standard. I checked Tix and it works well in Linux. The problem is with Windows, because the Tix documentation says Tix is installed with 2.2.2, the source Tix.py is broken and should be replaced with the source from the distribution. There is, in fact, a Tix.py file in the 'site-packages' folder, but replacing it does not make it work. This is the source and the error: import Tix root = Tix.Tk() Traceback (most recent call last): File "", line 1, in ? root = Tix.Tk() File "C:\PYTHON22\lib\lib-tk\Tix.py", line 211, in __init__ self.tk.eval('package require Tix') TclError: can't find package Tix Since there seem to be many paths out of this problem I would like to receive your suggestions before I set out to follow any one of them. Thank you, Gerardo From jepler at unpythonic.net Wed Mar 29 01:34:37 2006 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 28 Mar 2006 17:34:37 -0600 Subject: [Tkinter-discuss] Tix question [possibly off-topic] In-Reply-To: References: Message-ID: <20060328233436.GA3216@unpythonic.net> Tix support in Python comes in two parts: First, the Tix Python module, which is just an object-oriented wrapper. Second, the Tix package for tcl. The error you got indicates that the Tix package for tcl is not installed. On my system (Ubuntu 5.10), installing the debian package 'tix8.1' allowed your example script to execute successfully. Jeff From klappnase at web.de Wed Mar 29 11:16:01 2006 From: klappnase at web.de (Michael Lange) Date: Wed, 29 Mar 2006 11:16:01 +0200 Subject: [Tkinter-discuss] Tix question [possibly off-topic] In-Reply-To: References: Message-ID: <20060329111601.048c2053.klappnase@web.de> On Tue, 28 Mar 2006 16:09:36 -0500 (EST) Gerardo Juarez wrote: > > Hi, > > I need widgets which are a bit more elaborated than what Tk offers as > standard. I checked Tix and it works well in Linux. The problem is with > Windows, because the Tix documentation says Tix is installed with 2.2.2, > the source Tix.py is broken and should be replaced with the source from > the distribution. There is, in fact, a Tix.py file in the 'site-packages' > folder, but replacing it does not make it work. This is the source and the > error: > > import Tix > root = Tix.Tk() > > Traceback (most recent call last): > File "", line 1, in ? > root = Tix.Tk() > File "C:\PYTHON22\lib\lib-tk\Tix.py", line 211, in __init__ > self.tk.eval('package require Tix') > TclError: can't find package Tix > > Hi Gerardo, I think the above refers to the python Tix module only, not the tk extension. As far as I know they added this to the python distro later, with Python-2.3 or -2.4. So I think you might consider to upgrade python; if this is not an option you can install IDE-studio which should install the tix binaries into Python-2.2 (at least I got it working this way a while ago). You can find the IDE-studio installer somewhere on the Tix pages. I hope this helps Michael From rowen at cesmail.net Wed Mar 29 19:50:50 2006 From: rowen at cesmail.net (Russell E. Owen) Date: Wed, 29 Mar 2006 09:50:50 -0800 Subject: [Tkinter-discuss] tkFont issue; what patch will fly? Message-ID: Tkinter's support for tk named fonts has problems. tk named fonts allow one to change the font of a set of widgets all at the same time, e.g. to support user-specified fonts. One can create a tk named font, add an entry to the tk option database, and then new widgets of the appropriate type will automatically use that named font (by default). Very handy for user preferences! The Tkinter interface to tk named fonts is the tkFont.Font object. Originally tkFont.Font objects could create tk named fonts, but not visa versa (e.g. given a widget, you could not get a tkFont.Font representation of the named font it used), which was clumsy. I submitted a patch awhile ago that was *partly* implemented to fix this. Unfortunately, the part left out resulted in a mess that I'd like to clean up. The problem is garbage collection. At present all tkFont.Font objects delete their associated tk named font when they are garbage-collected. This was already a pain when the tkFont.Font object created the tk named font (since one had to keep the tkFont.Font object around even if one had no more use for it) but it's a disaster when the tkFont.Font is just a copy of an existing tk named font. My originally proposed solution was to never have tkFont.Font objects delete tk named fonts. I still think this is the best thing to do because one can create a tk named font and add it to the tk options database, then throw it away. To manipulate it later, just create a widget of the appropriate type, get a tkFont.Font object for its font, change that and throw it away again. However, that does mean a change in Tkinter behavior and a possible memory leak if somebody was mad enough to create hordes of named fonts, only to want to get rid of them later (I can't imagine a sane reason for doing that). An alternative is to have tkFont.Font only auto-delete the named font if the tkFont.Font was not a copy of an existing named font. Then at least one can safely get that copy and throw it away without hosing one's ability to manipulate widgets. I'll happily submit either patch (or some other if folks feel another alternative is better). What do you think? What will fly? -- Russell From geon at post.cz Wed Mar 29 22:25:43 2006 From: geon at post.cz (Pavel Kosina) Date: Wed, 29 Mar 2006 22:25:43 +0200 Subject: [Tkinter-discuss] tag_bind In-Reply-To: References: <4426F30D.2040403@post.cz> <20060327115000.5766989c.klappnase@web.de> <442818AD.3010208@post.cz><20060328131209.549aaaac.klappnase@web.de> <4429865E.7080107@post.cz> Message-ID: <442AED47.9070009@post.cz> Fredrik Lundh napsal(a): > keyboard events are always sent to the item that has focus, and > you can only set focus to items that support the insertion cursor > protocol. > > in stock tk/tkinter, "text" is the only item type that supports that > protocol. > Thank you, Fredrik. Pavel -- Pavel Kosina From jepler at unpythonic.net Wed Mar 29 23:07:42 2006 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 29 Mar 2006 15:07:42 -0600 Subject: [Tkinter-discuss] tkFont issue; what patch will fly? In-Reply-To: References: Message-ID: <20060329210742.GD13299@unpythonic.net> This sounds similar to the problem with Tk images and Python refcounting. If there's a better solution for fonts, maybe it can be applied to images too. If there's not a clearly better solution, fonts should do the same thing as images. Jeff From rowen at cesmail.net Thu Mar 30 00:07:37 2006 From: rowen at cesmail.net (Russell E. Owen) Date: Wed, 29 Mar 2006 14:07:37 -0800 Subject: [Tkinter-discuss] tkFont issue; what patch will fly? References: <20060329210742.GD13299@unpythonic.net> Message-ID: In article <20060329210742.GD13299 at unpythonic.net>, Jeff Epler wrote: > This sounds similar to the problem with Tk images and Python refcounting. > > If there's a better solution for fonts, maybe it can be applied to > images too. If there's not a clearly better solution, fonts should do > the same thing as images. I'm not sure this is a useful analogy because images are not like named fonts. An image is huge, so special memory management makes some sense. tk named fonts are tiny. An application may potentially handle huge #s of images (e.g. an image processing app), but there's no obvious reason for an application to have many named fonts. An image is visible; if it goes away you can see that immediately (even if it's confusing, at least you can see it when it happens). A tk named font is not visible; if it goes away it may be a long time before the application notices (e.g. next time one tries to adjust the displayed font for a set of widgets), making the issue very hard to track down. If there really is a valid use case for an application creating hordes of named fonts and ditching them later, then perhaps my second suggestion is necessary -- delete only when the tkFont.Font object that created the tk named font goes away, not if the tkFont.Font object is a copy of an existing named font. Personally I'd rather get rid of the __del__ method entirely and let tk named fonts persist. But either solution is clearly preferable to the current situation. -- Russell P.S. I'm curious...how many of you have used named fonts, and what do you use them for? I get the feeling they're not widely used. In my case I have a cross-platform app with a few user-settable fonts.