From raycores at gmail.com Sun Nov 4 22:26:22 2012 From: raycores at gmail.com (Lynn Oliver) Date: Sun, 4 Nov 2012 13:26:22 -0800 Subject: [Tkinter-discuss] question on horizontal scrolling with ttk.Treeview Message-ID: When using a horizontal scrollbar with the ttk.Treeview widget, xscrollcommand returns last = 1.0 unless the window is resized to less than the value for minwidth. So even if there is text displayed that is wider than minwidth you can't scroll to the portion that is beyond minwidth. Is there any way to change this behavior? BTW, if you insert a value into a Treeview widget that contains nulls, you get some very strange output displayed (characters mirrored across baseline): -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Screen Shot 2012-11-04 at 1.23.23 PM.jpeg Type: image/jpeg Size: 11882 bytes Desc: not available URL: From lionkimbro at gmail.com Sun Nov 4 22:39:50 2012 From: lionkimbro at gmail.com (Lion Kimbro) Date: Sun, 4 Nov 2012 13:39:50 -0800 Subject: [Tkinter-discuss] Attaching Widget Var to Widget? Message-ID: I'm trying to minimize maintenance of Var values. It is irritating that there is no method to get the check state of a Checkbutton, like there is to get the content of an Entry (.get). There is much out there on using the variable= parameter out there, but little on strategies for maintaining the variables. Are there any known problems with simply attaching a StringVar or IntVar to the Python widget it comes with? Ex: var=IntVar() chk=Checkbutton(frame, text="label", variable=var) chk.var=var Will there be any allocation/deal location problems with this? If the widget is destroyed via a grandparent or something, will any resources be left dangling? Anyone have any experience with this? I notice in the tk docs that a default variable is created if you don't make one yourself, and I am considering creating a StringVar using the name parameter such that it matches by querying the full path from the ID of the widget. From john at nmt.edu Sun Nov 4 23:22:06 2012 From: john at nmt.edu (John W. Shipman) Date: Sun, 4 Nov 2012 15:22:06 -0700 (MST) Subject: [Tkinter-discuss] Multiple images on a ttk widget? Message-ID: I'm currently attempting to learn the ttk widgets in the process of updating our locally written Tkinter reference manual. However, I am unable to reproduce the behavior described in this paragraph from the Python 2.7.3 library reference. This is from http://docs.python.org/2.7/library/ttk.html, in the section on the ttk.Widget class, the table of "Label Options": image: Specifies an image to display. This is a list of 1 or more elements. The first element is the default image name. The rest of the list is a sequence of statespec/value pairs as defined by Style.map(), specifying different images to use when the widget is in a particular state or a combination of states. All images in the list should have the same size. First of all, image names don't work. I was able to get a ttk.Label to display an image by using image=t, where t is an instance of ImageTk.PhotoImage. For the rest of it, after an hour of trying I was unable to get the state-dependent image changing to work. If anyone has a working example of this, I would greatly appreciate it! Best regards, John Shipman (john at nmt.edu), Applications Specialist New Mexico Tech Computer Center, Speare 146, Socorro, NM 87801 (575) 835-5735, http://www.nmt.edu/~john ``Let's go outside and commiserate with nature.'' --Dave Farber P.S. Here's a preview of the new stuff. This is the section on the Treeview widget, which I think I understand now: From john at nmt.edu Sun Nov 4 23:26:49 2012 From: john at nmt.edu (John W. Shipman) Date: Sun, 4 Nov 2012 15:26:49 -0700 (MST) Subject: [Tkinter-discuss] Multiple images on a ttk widget? (correction) Message-ID: Oops, the URL somehow got cut off after this: +-- | P.S. Here's a preview of the new stuff. This is the section on | the Treeview widget, which I think I understand now: +-- http://www.nmt.edu/tcc/help/pubs/tkinter85/web/ttk-Treeview.html John Shipman (john at nmt.edu), Applications Specialist New Mexico Tech Computer Center, Speare 146, Socorro, NM 87801 (575) 835-5735, http://www.nmt.edu/~john ``Let's go outside and commiserate with nature.'' --Dave Farber From klappnase at web.de Mon Nov 5 20:20:05 2012 From: klappnase at web.de (Michael Lange) Date: Mon, 5 Nov 2012 20:20:05 +0100 Subject: [Tkinter-discuss] Attaching Widget Var to Widget? In-Reply-To: References: Message-ID: <20121105202005.f072491c.klappnase@web.de> On Sun, 4 Nov 2012 13:39:50 -0800 Lion Kimbro wrote: > I'm trying to minimize maintenance of Var values. It is irritating that > there is no method to get the check state of a Checkbutton, like there > is to get the content of an Entry (.get). > > There is much out there on using the variable= parameter out there, but > little on strategies for maintaining the variables. > > Are there any known problems with simply attaching a StringVar or > IntVar to the Python widget it comes with? > > Ex: > > var=IntVar() > chk=Checkbutton(frame, text="label", variable=var) > chk.var=var > > Will there be any allocation/deal location problems with this? > If the widget is destroyed via a grandparent or something, will any > resources be left dangling? Anyone have any experience with this? > > I notice in the tk docs that a default variable is created if you don't > make one yourself, and I am considering creating a StringVar using the > name parameter such that it matches by querying the full path from the > ID of the widget. If you have to handle a lot of checkbuttons in your application a custom checkbutton class with its own associated variable might come in handy, as in this example: import tkinter class CheckButton(tkinter.Checkbutton): def __init__(self, master, **kw): if 'variable' in kw: self._var = kw['variable'] tkinter.Checkbutton.__init__(self, master, **kw) if not 'variable' in kw: self._var = tkinter.BooleanVar(self, value=False) self.configure(variable=self._var) def get(self): return self._var.get() def set(self, value): self._var.set(value) root = tkinter.Tk() cb = CheckButton(root, text='Test') cb.pack(padx=100, pady=100) def test(ev): print(cb.get()) root.bind('', test) root.mainloop() Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. You're dead, Jim. -- McCoy, "The Tholian Web", stardate unknown From klappnase at web.de Mon Nov 5 21:04:57 2012 From: klappnase at web.de (Michael Lange) Date: Mon, 5 Nov 2012 21:04:57 +0100 Subject: [Tkinter-discuss] Multiple images on a ttk widget? In-Reply-To: References: Message-ID: <20121105210457.059a8055.klappnase@web.de> Hi John, On Sun, 4 Nov 2012 15:22:06 -0700 (MST) "John W. Shipman" wrote: > I'm currently attempting to learn the ttk widgets in the process > of updating our locally written Tkinter reference manual. > > However, I am unable to reproduce the behavior described in this > paragraph from the Python 2.7.3 library reference. This is > from http://docs.python.org/2.7/library/ttk.html, in the > section on the ttk.Widget class, the table of "Label Options": > > image: Specifies an image to display. This is a list of 1 or > more elements. The first element is the default image > name. The rest of the list is a sequence of statespec/value > pairs as defined by Style.map(), specifying different images > to use when the widget is in a particular state or a > combination of states. All images in the list should have the > same size. > > First of all, image names don't work. I was able to get a > ttk.Label to display an image by using image=t, where t is an > instance of ImageTk.PhotoImage. Looks like this paragraph was copy-and-pasted from man ttk_widget, in tkinter it surely must be a PhotoImage. > > For the rest of it, after an hour of trying I was unable to get > the state-dependent image changing to work. If anyone has a > working example of this, I would greatly appreciate it! >From the docs this seemed quite confusing to me either. After some tries I came up with the following which seems to work: ######################################### import tkinter from tkinter import ttk root = tkinter.Tk() img1 = tkinter.PhotoImage(file='gnome-netstatus-idle.gif') img2 = tkinter.PhotoImage(file='gnome-netstatus-txrx.gif') img3 = tkinter.PhotoImage(file='gnome-netstatus-error.gif') l = ttk.Label(root,image=(img1, 'selected', img2, 'active', img3)) l.pack(padx=100, pady=100) def test(event): if 'selected' in l.state(): l.state(('!selected',)) else: l.state(('selected',)) def test2(event): if 'active' in l.state(): l.state(('!active',)) else: l.state(('active',)) root.bind('', test) root.bind('', test2) root.mainloop() ######################################### Apparently the image-list must be of the form (default-image, statespec1, img1, statespec2, img2...), where statespecs may be strings or sequences as in this more complex example: l = ttk.Label(root,image=(img1, ('!active', 'selected'), img2, ('active', '!selected'), img3, ('active', 'selected'), img4)) Best regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Youth doesn't excuse everything. -- Dr. Janice Lester (in Kirk's body), "Turnabout Intruder", stardate 5928.5. From lionkimbro at gmail.com Mon Nov 5 23:41:29 2012 From: lionkimbro at gmail.com (Lion Kimbro) Date: Mon, 5 Nov 2012 14:41:29 -0800 Subject: [Tkinter-discuss] Attaching Widget Var to Widget? In-Reply-To: <20121105202005.f072491c.klappnase@web.de> References: <20121105202005.f072491c.klappnase@web.de> Message-ID: Cute, I like it. I'm attaching the tkinter control variable to the tkinter widget object for now, but I'll keep this in mind for the future. On Mon, Nov 5, 2012 at 11:20 AM, Michael Lange wrote: > On Sun, 4 Nov 2012 13:39:50 -0800 > Lion Kimbro wrote: > > > I'm trying to minimize maintenance of Var values. It is irritating that > > there is no method to get the check state of a Checkbutton, like there > > is to get the content of an Entry (.get). > > > > There is much out there on using the variable= parameter out there, but > > little on strategies for maintaining the variables. > > > > Are there any known problems with simply attaching a StringVar or > > IntVar to the Python widget it comes with? > > > > Ex: > > > > var=IntVar() > > chk=Checkbutton(frame, text="label", variable=var) > > chk.var=var > > > > Will there be any allocation/deal location problems with this? > > If the widget is destroyed via a grandparent or something, will any > > resources be left dangling? Anyone have any experience with this? > > > > I notice in the tk docs that a default variable is created if you don't > > make one yourself, and I am considering creating a StringVar using the > > name parameter such that it matches by querying the full path from the > > ID of the widget. > > If you have to handle a lot of checkbuttons in your application a custom > checkbutton class with its own associated variable might come in handy, > as in this example: > > import tkinter > > class CheckButton(tkinter.Checkbutton): > def __init__(self, master, **kw): > if 'variable' in kw: > self._var = kw['variable'] > tkinter.Checkbutton.__init__(self, master, **kw) > if not 'variable' in kw: > self._var = tkinter.BooleanVar(self, value=False) > self.configure(variable=self._var) > def get(self): > return self._var.get() > def set(self, value): > self._var.set(value) > > root = tkinter.Tk() > cb = CheckButton(root, text='Test') > cb.pack(padx=100, pady=100) > def test(ev): > print(cb.get()) > root.bind('', test) > root.mainloop() > > > Regards > > Michael > > > .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. > > You're dead, Jim. > -- McCoy, "The Tholian Web", stardate unknown > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mohsen.jadidi at gmail.com Wed Nov 14 16:29:31 2012 From: mohsen.jadidi at gmail.com (llvllj) Date: Wed, 14 Nov 2012 07:29:31 -0800 (PST) Subject: [Tkinter-discuss] Segfault in Image.PhotoImage on OS X In-Reply-To: References: Message-ID: <1352906971660-4995857.post@n6.nabble.com> I still have problem with this issue and I don't know what I'm doing wrong. objc[1296]: Class TKApplication is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined. objc[1296]: Class TKMenu is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined. objc[1296]: Class TKContentView is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined. objc[1296]: Class TKWindow is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined. Here is my otool -L Tk on both paths : on "/Library/Frameworks/Tk.framework/Versions/8.5" Tk: /Library/Frameworks/Tk.framework/Versions/8.5/Tk (compatibility version 8.5.0, current version 8.5.11) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0) /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 550.29.0) /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 15.0.0) /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 152.0.0) /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0) /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 625.0.0) /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0) /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 44.0.0) /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 38.0.0) /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 751.29.0) /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1038.32.0) on /System/Library/Frameworks/Tk.framework/Versions/8.5 : Tk: /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk (compatibility version 8.5.0, current version 8.5.9) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.0.0) /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 629.0.0) /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 17.0.0) /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 153.0.0) /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0) /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0) /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 53.0.0) /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 41.0.0) /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 829.0.0) /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1125.0.0) and this is what I did: sudo install_name_tool -change /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk /Library/Frameworks/Tk.framework/Versions/8.5/Tk Tk but after that nothing changed at all. Can you provide me with more detail. I am not much familiar with Linker and C stuff. Thanks. -- View this message in context: http://python.6.n6.nabble.com/Segfault-in-Image-PhotoImage-on-OS-X-tp4931170p4995857.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From kw at codebykevin.com Wed Nov 14 19:48:22 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Wed, 14 Nov 2012 13:48:22 -0500 Subject: [Tkinter-discuss] Segfault in Image.PhotoImage on OS X In-Reply-To: <1352906971660-4995857.post@n6.nabble.com> References: <1352906971660-4995857.post@n6.nabble.com> Message-ID: It's likely that a Tk or Python library is linking against one framework and Tk itself links against another. You'll have to run install_name_tool on the offending library. Sent from my iPhone On Nov 14, 2012, at 10:29 AM, llvllj wrote: > I still have problem with this issue and I don't know what I'm doing wrong. > > objc[1296]: Class TKApplication is implemented in both > /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and > /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be > used. Which one is undefined. > objc[1296]: Class TKMenu is implemented in both > /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and > /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be > used. Which one is undefined. > objc[1296]: Class TKContentView is implemented in both > /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and > /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be > used. Which one is undefined. > objc[1296]: Class TKWindow is implemented in both > /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and > /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be > used. Which one is undefined. > > > Here is my otool -L Tk on both paths : > > on "/Library/Frameworks/Tk.framework/Versions/8.5" > > Tk: > /Library/Frameworks/Tk.framework/Versions/8.5/Tk (compatibility > version 8.5.0, current version 8.5.11) > /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current > version 125.2.0) > > /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation > (compatibility version 150.0.0, current version 550.29.0) > /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa > (compatibility version 1.0.0, current version 15.0.0) > /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon > (compatibility version 2.0.0, current version 152.0.0) > /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit > (compatibility version 1.0.0, current version 275.0.0) > /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current > version 625.0.0) > /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current > version 227.0.0) > > /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices > (compatibility version 1.0.0, current version 44.0.0) > > /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices > (compatibility version 1.0.0, current version 38.0.0) > > /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation > (compatibility version 300.0.0, current version 751.29.0) > /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit > (compatibility version 45.0.0, current version 1038.32.0) > > on /System/Library/Frameworks/Tk.framework/Versions/8.5 : > > > Tk: /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk (compatibility > version 8.5.0, current version 8.5.9) > /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current > version 159.0.0) > > /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation > (compatibility version 150.0.0, current version 629.0.0) > /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa > (compatibility version 1.0.0, current version 17.0.0) > /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon > (compatibility version 2.0.0, current version 153.0.0) > /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit > (compatibility version 1.0.0, current version 275.0.0) > /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current > version 228.0.0) > > /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices > (compatibility version 1.0.0, current version 53.0.0) > > /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices > (compatibility version 1.0.0, current version 41.0.0) > > /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation > (compatibility version 300.0.0, current version 829.0.0) > /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit > (compatibility version 45.0.0, current version 1125.0.0) > > > and this is what I did: > > > sudo install_name_tool -change > /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk > /Library/Frameworks/Tk.framework/Versions/8.5/Tk Tk > > but after that nothing changed at all. > Can you provide me with more detail. I am not much familiar with Linker and > C stuff. > Thanks. > > > > -- > View this message in context: http://python.6.n6.nabble.com/Segfault-in-Image-PhotoImage-on-OS-X-tp4931170p4995857.html > Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss From kw at codebykevin.com Thu Nov 15 03:20:05 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Wed, 14 Nov 2012 21:20:05 -0500 Subject: [Tkinter-discuss] Segfault in Image.PhotoImage on OS X In-Reply-To: References: <1352906971660-4995857.post@n6.nabble.com> Message-ID: <50A45155.9080402@codebykevin.com> On 11/14/12 1:51 PM, mohsen jadidi wrote: > Can you explain in more detail? what is wrong with my install_name_tool? > what do you mean by offending library? > > > On Wed, Nov 14, 2012 at 7:48 PM, Kevin Walzer > wrote: > > It's likely that a Tk or Python library is linking against one > framework and Tk itself links against another. You'll have to run > install_name_tool on the offending library. Rather than running otool -L against the Python and Tk frameworks, run it against tkinter.so, and whatever shared objects/dylibs are part of the Imaging extension. They should be linked against the same framework as tkinter.so. The install_name_tool CLI program can fix this. See man install_name_tool for more information. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From john at nmt.edu Wed Nov 28 06:30:16 2012 From: john at nmt.edu (John W. Shipman) Date: Tue, 27 Nov 2012 22:30:16 -0700 (MST) Subject: [Tkinter-discuss] Can't configure ttk.Entry font Message-ID: Below my signature is a trivial ttk script with two widgets: an Entry and a quit button. Styling the font on the quit button works great. But styling the font on the Entry widget does not; I always get the default font, which is a bit small for many people over the age of 40. I've tried a number of things, but either I'm missing something really stupid in my code, or there is a defect in the ttk.Entry code that it does not pick up a font. Here's our version: >>> tk.__version__ '$Revision: 81008 $' >>> ttk.__version__ '0.3.1' I would appreciate any suggestions. Best regards, John Shipman (john at nmt.edu), Applications Specialist New Mexico Tech Computer Center, Speare 146, Socorro, NM 87801 (575) 835-5735, http://www.nmt.edu/~john ``Let's go outside and commiserate with nature.'' --Dave Farber ================================================================ #!/usr/bin/env python # wtfentry: Why can't I specify a font on a ttk.Entry? # Submitted by John W. Shipman, john at nmt.edu import sys import ttk import Tkinter as tk import tkFont class App(ttk.Frame): def __init__(self): ttk.Frame.__init__(self, None) self.grid() self._styling() self._createWidgets() def _styling(self): self._mainFont = tkFont.Font(family='Helvetica', size=20, slant='italic') self._entryFont = tkFont.Font(family='Helvetica', size=36) self._entryStyle = ttk.Style() self._entryStyle.configure('My.TEntry', font=self._entryFont) self._buttonStyle = ttk.Style() self._buttonStyle.configure('My.TButton', font=self._mainFont) def _createWidgets(self): self._entryVar = tk.StringVar() self._entryVar.set('initial value') self._entry = ttk.Entry(self, style='My.TEntry', textvariable=self._entryVar) self._entry.grid() self._quitButton = ttk.Button(self, text='Quit', style='My.TButton', command=self.quit) self._quitButton.grid() app = App() app.mainloop() From klappnase at web.de Wed Nov 28 13:47:24 2012 From: klappnase at web.de (Michael Lange) Date: Wed, 28 Nov 2012 13:47:24 +0100 Subject: [Tkinter-discuss] Can't configure ttk.Entry font In-Reply-To: References: Message-ID: <20121128134724.ead13203.klappnase@web.de> Hi John, On Tue, 27 Nov 2012 22:30:16 -0700 (MST) "John W. Shipman" wrote: > Below my signature is a trivial ttk script with two widgets: an > Entry and a quit button. Styling the font on the quit button > works great. But styling the font on the Entry widget does not; > I always get the default font, which is a bit small for many > people over the age of 40. > > I've tried a number of things, but either I'm missing something > really stupid in my code, or there is a defect in the ttk.Entry > code that it does not pick up a font. > > Here's our version: > > >>> tk.__version__ > '$Revision: 81008 $' > >>> ttk.__version__ > '0.3.1' here (debian squeeze) it is the same, however if I change your example a little into: self._entry = ttk.Entry(self, font=('helvetica', '30'), textvariable=self._entryVar) self._entry.grid() the requested font is actually used. I guess this is a bug in man ttk_entry, which does not mention the font configuration option. Now when I try: print(self._entryStyle.configure('TEntry')) the result is {'padding': 1, 'relief': 'sunken', 'fieldbackground': 'white'} whereas print(self._entry.cget('font')) returns TkTextFont So apparently the default entry style does not define a font at all, but the ttk entry uses a standard tk font instead and ignores fonts defined in styles. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. "That unit is a woman." "A mass of conflicting impulses." -- Spock and Nomad, "The Changeling", stardate 3541.9 From andreas.ostermann.11 at googlemail.com Fri Nov 30 15:45:57 2012 From: andreas.ostermann.11 at googlemail.com (Andreas Ostermann) Date: Fri, 30 Nov 2012 15:45:57 +0100 Subject: [Tkinter-discuss] Proposal to use dynamic proxy with tkinter to communicate with background thread Message-ID: Hi! I was currently searching for the possibility to communicate between tkinter and a python background thread. I hoped for something like java's invokeLater mechanism. I found a lot of ideas, using a Queue for the communication and then poll in Tkinter on the Queue, raising the question which interval should be used. Then there was mentioned to use the after_idle() method to pass something into the Tk loop, but the method is not thread_safe as it seems. And then there was the idea of binding events to methods and to raise the event so that method will be called. It seems, that this is still a valid question, so I would like to share my solution and open it for discussion and hope you would review it and show me problems if there are any. First I want something like the invokeLater call from java, so I created to classes which will be "listener", one for the tk loop and one as a background thread: class BackgroundListener (threading.Thread) : def __init__(self): threading.Thread.__init__(self) self.queue = Queue.Queue() self.cancel = threading.Event() def invokeLater(self, delegate): self.queue.put(delegate) def interrupt(self) : self.cancel.set() def run(self): while not self.cancel.isSet() : try : delegate = self.queue.get(timeout=0.5) if not self.cancel.isSet() : # don't call if already finished ! delegate() except Queue.Empty : pass class TkListener : def __init__(self, tk) : self.queue = Queue.Queue() self.tk = tk self.event = "<<%s>>" % uuid.uuid1() tk.bind(self.event, self.invoke) def invokeLater(self, delegate) : self.queue.put(delegate) self.tk.event_generate(self.event, when='tail') def invoke(self, event) : try : while True : delegate = self.queue.get(block=False) delegate() except Queue.Empty : pass So, what happens here? The Background thread will store the delegate object (see below) into a Queue and the background thread is reading from this Queue, as Queue is threadsafe everything is fine. (I misuse the Event to create something like the interrupt() call from java) The TkListener will get a reference to the tk object and binds a event to it which calls a the invoke method. Therefore it is similar to the other listener. The invokeLater call adds the delegate to the Queue, then raise the event. The tkloop will then handle the event by calling the invoke method, where all waiting delegates are removed from the queue and called. So whats with the delegate class? Its part of a dynamic proxy implementation which can be used for any other purpose as long as the listener you provide has an invokeLater method. And that's what they look like: class Delegate : def __init__(self, real, name, args, kwargs) : self.real = real self.name = name self.args = args self.kwargs = kwargs def __call__(self) : method = getattr(self.real, self.name) apply(method, self.args, self.kwargs) class Delegator : def __init__(self, listener, real, name) : self.listener = listener self.real = real self.name = name def __call__(self, *args, **kwargs) : delegate = Delegate(self.real, self.name, args, kwargs) self.listener.invokeLater(delegate) class Proxy : def __init__(self, listener, real) : self.listener = listener self.real = real self.cache = {} def __getattr__(self, name) : try : delegator = self.cache[name] except KeyError : delegator = Delegator(self.listener, self.real, name) self.cache[name] = delegator return delegator The Proxy class will hold the listener and the real object. When you call a method on the proxy a delegator object for the method name is generated and cached. Then the delegator is returned and the caller call will be handled in the delegator. The delegator then creates a delegate object holding all the informations and the attributes of the call and the delegate object will be hand over to the listener via the invokeLater method. As you have seen above the listener will then get the delegate object from the Queue and call it, which leads to a call to the real object in the context of the listener. And at last, so that you have something to play around with, some test classes showing different ways on how to use the proxy object, even for callbacks over thread boundaries: import Tkinter import Queue import uuid import threading import thread class MyTkinterObject: def __init__(self, tk): frame = Tkinter.Frame(tk) self.quitButton = Tkinter.Button(frame, text="QUIT", fg="red", command=frame.quit) self.quitButton.pack(side=Tkinter.LEFT) self.helloButton = Tkinter.Button(frame, text="Hello") self.helloButton.pack(side=Tkinter.LEFT) self.hello2Button = Tkinter.Button(frame, text="Hello2", command=self.trigger2) self.hello2Button.pack(side=Tkinter.LEFT) frame.pack() def register(self, myBackgroundObject) : self.helloButton.bind("", myBackgroundObject.trigger) def trigger(self, callback) : print "%s - Front hello" % thread.get_ident() callback() def trigger2(self) : print "%s - Front hello" % thread.get_ident() class MyBackgroundObject : def __init__(self, listener): self.proxy = Proxy(listener, self) def register(self, myTkinterObject) : self.myTkinterObject = myTkinterObject def trigger(self, event) : print "%s - Back hello - %s" % (thread.get_ident(), event) self.myTkinterObject.trigger(self.proxy.callback) def callback(self) : print "%s - Back bye" % thread.get_ident() def main() : root = Tkinter.Tk() tkListener = TkListener(root) backgroundListener = BackgroundListener() myTkinterObject = MyTkinterObject(root) myBackgroundObject = MyBackgroundObject(backgroundListener) myTkinterObject.register(myBackgroundObject.proxy) myBackgroundObject.register(Proxy(tkListener, myTkinterObject)) backgroundListener.start() root.mainloop() backgroundListener.interrupt() if __name__ == "__main__": main() I would like to hear your comments! thanks, AO