From contropinion at gmail.com Sun Jul 1 08:52:55 2012 From: contropinion at gmail.com (contro opinion) Date: Sun, 1 Jul 2012 14:52:55 +0800 Subject: [Tkinter-discuss] how to use tkinter in python3.2 Message-ID: 1.i have installed tk 2.install python3.1 and python3.2 the sameway 1)download 2)./configure 3)make 4)make install in my console tiger at ocean:~$ python3.2 Python 3.2.3 (default, Jul 1 2012, 11:07:14) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.2/tkinter/__init__.py", line 39, in import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter >>> tiger at ocean:~$ python3.1 Python 3.1.3 (r313:86834, Nov 28 2010, 11:28:10) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter >>> what is the matter? -------------- next part -------------- An HTML attachment was scrubbed... URL: From psaoflamand at live.com Sun Jul 1 11:22:31 2012 From: psaoflamand at live.com (psao pollard-flamand) Date: Sun, 1 Jul 2012 02:22:31 -0700 Subject: [Tkinter-discuss] how to use tkinter in python3.2 Message-ID: The module name is Tkinter not tkinter... ________________________________ From: contro opinion Sent: 30/06/2012 11:53 PM To: Tkinter-discuss Subject: [Tkinter-discuss] how to use tkinter in python3.2 1.i have installed tk 2.install python3.1 and python3.2 the sameway 1)download 2)./configure 3)make 4)make install in my console tiger at ocean:~$ python3.2 Python 3.2.3 (default, Jul 1 2012, 11:07:14) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.2/tkinter/__init__.py", line 39, in import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter >>> tiger at ocean:~$ python3.1 Python 3.1.3 (r313:86834, Nov 28 2010, 11:28:10) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter >>> what is the matter? -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org http://mail.python.org/mailman/listinfo/tkinter-discuss From klappnase at web.de Sun Jul 1 13:08:59 2012 From: klappnase at web.de (Michael Lange) Date: Sun, 1 Jul 2012 13:08:59 +0200 Subject: [Tkinter-discuss] how to use tkinter in python3.2 In-Reply-To: References: Message-ID: <20120701130859.63503420.klappnase@web.de> Thus spoketh psao pollard-flamand unto us on Sun, 1 Jul 2012 02:22:31 -0700: > The module name is Tkinter not tkinter... Not in Python3, tkinter is correct. > ________________________________ > From: contro opinion > Sent: 30/06/2012 11:53 PM > To: Tkinter-discuss > Subject: [Tkinter-discuss] how to use tkinter in python3.2 > > 1.i have installed tk > 2.install python3.1 and python3.2 the sameway > 1)download > 2)./configure > 3)make > 4)make install > > in my console > > > tiger at ocean:~$ python3.2 > Python 3.2.3 (default, Jul 1 2012, 11:07:14) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import tkinter > Traceback (most recent call last): > File "", line 1, in > File "/usr/local/lib/python3.2/tkinter/__init__.py", line 39, in > import _tkinter # If this fails your Python may not be > configured for Tk ImportError: No module named _tkinter > >>> > > tiger at ocean:~$ python3.1 > Python 3.1.3 (r313:86834, Nov 28 2010, 11:28:10) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import tkinter > >>> > what is the matter? Apparently in Python-3.2 ./configure failed to detect the Tcl/Tk install. Maybe something on your system was changed in between the install of 3.1 and 3.2 ? We had a similar discussion here a while ago: http://mail.python.org/pipermail/tkinter-discuss/2012-June/003203.html Unfortunately there do not seem to be much resources helping with these kind of problems, I encountered them myself, too, and never came to a really satisfying solution. If ./configure fails to find tcl/tk while all the libs and header files are properly installed, usually the paths pointing to tclConfig.sh and tkConfig.sh must be added to some environment variable like LD_LIBRARY_PATH or LIBDIR , maybe the the paths to tcl.h and tk.h must also be explicitely added to some other environment variable. Alas there does not seem to be the one solution that works in any case, at least I never saw it. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. You're too beautiful to ignore. Too much woman. -- Kirk to Yeoman Rand, "The Enemy Within", stardate unknown From michael.odonnell at uam.es Mon Jul 2 00:38:14 2012 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Mon, 2 Jul 2012 08:38:14 +1000 Subject: [Tkinter-discuss] how to use tkinter in python3.2 In-Reply-To: <20120701130859.63503420.klappnase@web.de> References: <20120701130859.63503420.klappnase@web.de> Message-ID: Try installing the ActivePython installation, and which has TCL/TK installed. They do not need to be installed separately in any case, both the ActivePython and official releases include all libraries needed for tkinter. Mick On Sun, Jul 1, 2012 at 9:08 PM, Michael Lange wrote: > Thus spoketh psao pollard-flamand > unto us on Sun, 1 Jul 2012 02:22:31 -0700: > >> The module name is Tkinter not tkinter... > > Not in Python3, tkinter is correct. > >> ________________________________ >> From: contro opinion >> Sent: 30/06/2012 11:53 PM >> To: Tkinter-discuss >> Subject: [Tkinter-discuss] how to use tkinter in python3.2 >> >> 1.i have installed tk >> 2.install python3.1 and python3.2 the sameway >> 1)download >> 2)./configure >> 3)make >> 4)make install >> >> in my console >> >> >> tiger at ocean:~$ python3.2 >> Python 3.2.3 (default, Jul 1 2012, 11:07:14) >> [GCC 4.4.5] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import tkinter >> Traceback (most recent call last): >> File "", line 1, in >> File "/usr/local/lib/python3.2/tkinter/__init__.py", line 39, in >> import _tkinter # If this fails your Python may not be >> configured for Tk ImportError: No module named _tkinter >> >>> >> >> tiger at ocean:~$ python3.1 >> Python 3.1.3 (r313:86834, Nov 28 2010, 11:28:10) >> [GCC 4.4.5] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import tkinter >> >>> >> what is the matter? > > Apparently in Python-3.2 ./configure failed to detect the Tcl/Tk install. > Maybe something on your system was changed in between the install of 3.1 > and 3.2 ? > We had a similar discussion here a while ago: > http://mail.python.org/pipermail/tkinter-discuss/2012-June/003203.html > > Unfortunately there do not seem to be much resources helping with these > kind of problems, I encountered them myself, too, and never came to a > really satisfying solution. > If ./configure fails to find tcl/tk while all the libs and header files > are properly installed, usually the paths pointing to tclConfig.sh and > tkConfig.sh must be added to some environment variable like > LD_LIBRARY_PATH or LIBDIR , maybe the the paths to tcl.h and tk.h must > also be explicitely added to some other environment variable. > Alas there does not seem to be the one solution that works in any case, > at least I never saw it. > > Regards > > Michael > > > .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. > > You're too beautiful to ignore. Too much woman. > -- Kirk to Yeoman Rand, "The Enemy Within", stardate > unknown > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss -- Not sent from my iPhone From mid.tier at gmail.com Thu Jul 5 08:17:39 2012 From: mid.tier at gmail.com (mid.tier) Date: Thu, 5 Jul 2012 12:17:39 +0600 Subject: [Tkinter-discuss] pytkapp - python package to develop a simple application (MDI/SDI) using tkinter library. Message-ID: Good day, I uploaded initial release for pytkapp package (former pytkmdiapp) for fast develop tkinter-based application with MDI/SDI interface. Features: Tested under python 2.6, 2.7, 3.1 Platform-independent (testing on win xp, 7, ubuntu, fedora) Contains set of useful (on my view ;-)) widgets and tools Contains updated tablelist wrapper for tcl package tablelist (http://www.nemethi.de) You can download package from PyPi: http://pypi.python.org/pypi/pytkapp From list at qtrac.plus.com Thu Jul 12 12:38:37 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Thu, 12 Jul 2012 11:38:37 +0100 Subject: [Tkinter-discuss] Toggle buttons Message-ID: <20120712113837.5241e55f@dino> Hi, I want to create a toggle button, i.e., a button that when clicked goes down (if it is up) and goes up (if it is down). One easy way to achieve this is to set the button's style to "Toolbutton" (see self.toggle2). But unfortunately, that gets rid of the button's relief so it looks out of place amongst other non-toggling buttons. I solved if for Linux using a custom style (see self.toggle3). But this doesn't work on Windows and I can't figure out how to solve it. Can anyone suggest a solution? Here's the code I've got: ############################################################ import tkinter.ttk class Window(tkinter.ttk.Frame): def __init__(self, master=None): super().__init__(master) self.toggle1 = tkinter.ttk.Button(text="Off", command=lambda *args: self.toggle(self.toggle1)) self.toggle1.pack(padx=5, pady=5) self.toggle2 = tkinter.ttk.Button(text="Off", style="Toolbutton", command=lambda *args: self.toggle(self.toggle2)) self.toggle2.pack(padx=5, pady=5) self.toggle3 = tkinter.ttk.Button(text="Off", command=lambda *args: self.toggle(self.toggle3)) self.toggle3.pack(padx=5, pady=5) style = tkinter.ttk.Style() style.configure("Toggle.TButton") style.map("Toggle.TButton", relief=[("pressed", "sunken"), ("selected", "sunken"), ("!selected", "raised")]) self.toggle3.config(style="Toggle.TButton") tkinter.ttk.Button(text="Quit", command=self.master.destroy).pack(padx=5, pady=5) self.pack() def toggle(self, button): if button.instate(("!selected",)): button.state(("selected",)) button.config(text="On") else: button.state(("!selected",)) button.config(text="Off") window = Window() window.master.title("Toggle") window.master.mainloop() ############################################################ Thanks! -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Programming in Python 3" - ISBN 0321680561 http://www.qtrac.eu/py3book.html From klappnase at web.de Thu Jul 12 19:13:36 2012 From: klappnase at web.de (Michael Lange) Date: Thu, 12 Jul 2012 19:13:36 +0200 Subject: [Tkinter-discuss] Toggle buttons In-Reply-To: <20120712113837.5241e55f@dino> References: <20120712113837.5241e55f@dino> Message-ID: <20120712191336.748e3b98.klappnase@web.de> Hi, Thus spoketh Mark Summerfield unto us on Thu, 12 Jul 2012 11:38:37 +0100: > Hi, > > I want to create a toggle button, i.e., a button that when clicked goes > down (if it is up) and goes up (if it is down). > > One easy way to achieve this is to set the button's style to > "Toolbutton" (see self.toggle2). But unfortunately, that gets rid of the > button's relief so it looks out of place amongst other non-toggling > buttons. > > I solved if for Linux using a custom style (see self.toggle3). But this > doesn't work on Windows and I can't figure out how to solve it. > > Can anyone suggest a solution? Maybe you could use a Checkbutton with indicatoron=False, as in: import tkinter root = tkinter.Tk() def toggle(button, variable): if variable.get(): button.config(text='On') else: button.config(text='Off') v1 = tkinter.BooleanVar() v1.set(False) b1 = tkinter.Checkbutton(root, text='Off', variable=v1, indicatoron=False, selectcolor='', command=lambda : toggle(b1, v1)) b1.pack(padx=50, pady=50) root.mainloop() The button in this example looks tiny compared to a Button(), but this could probably easily be fixed. Unfortunately there does not seem to be a indicatoron Option for the ttk.Checkbutton though, and I am not sure how good or bad this will look on windows. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. You! What PLANET is this! -- McCoy, "The City on the Edge of Forever", stardate 3134.0 From list at qtrac.plus.com Fri Jul 13 09:35:20 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Fri, 13 Jul 2012 08:35:20 +0100 Subject: [Tkinter-discuss] Toggle buttons In-Reply-To: <20120712191336.748e3b98.klappnase@web.de> References: <20120712113837.5241e55f@dino> <20120712191336.748e3b98.klappnase@web.de> Message-ID: <20120713083520.78d2eff9@dino> Hi Michael, On Thu, 12 Jul 2012 19:13:36 +0200 Michael Lange wrote: > Hi, > > Thus spoketh Mark Summerfield > unto us on Thu, 12 Jul 2012 11:38:37 +0100: > > > Hi, > > > > I want to create a toggle button, i.e., a button that when clicked goes > > down (if it is up) and goes up (if it is down). > > > > One easy way to achieve this is to set the button's style to > > "Toolbutton" (see self.toggle2). But unfortunately, that gets rid of > > the button's relief so it looks out of place amongst other non-toggling > > buttons. > > > > I solved if for Linux using a custom style (see self.toggle3). But this > > doesn't work on Windows and I can't figure out how to solve it. > > > > Can anyone suggest a solution? > > Maybe you could use a Checkbutton with indicatoron=False, as in: > > import tkinter > > root = tkinter.Tk() > > def toggle(button, variable): > if variable.get(): > button.config(text='On') > else: > button.config(text='Off') > > v1 = tkinter.BooleanVar() > v1.set(False) > b1 = tkinter.Checkbutton(root, text='Off', variable=v1, > indicatoron=False, selectcolor='', command=lambda : toggle(b1, v1)) > b1.pack(padx=50, pady=50) > > root.mainloop() > > The button in this example looks tiny compared to a Button(), but this > could probably easily be fixed. Unfortunately there does not seem to be a > indicatoron Option for the ttk.Checkbutton though, and I am not sure how > good or bad this will look on windows. Unfortunately it looks bad on Windows because using tkinter.Checkbutton rather than tkinter.ttk.Checkbutton means you get a button that isn't styled so it looks completely different from the others. I'll probably use "on" and "off" images on Windows. Thanks! -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Advanced Qt Programming" - ISBN 0321635906 http://www.qtrac.eu/aqpbook.html From markus.holub at bluebottle.com Fri Jul 13 17:56:07 2012 From: markus.holub at bluebottle.com (Markus Holub) Date: Fri, 13 Jul 2012 17:56:07 +0200 Subject: [Tkinter-discuss] pybwidget notebook bug Message-ID: <50004517.6010308@bluebottle.com> 'delete' is defined twice in the NoteBook class. Moreover the second definition misses the 'destroyframe' argument, making this argument unusable. The 'delete' call in 'getframe' seems also incorrect. Regards, Markus From michael.odonnell at uam.es Mon Jul 23 03:22:20 2012 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Mon, 23 Jul 2012 11:22:20 +1000 Subject: [Tkinter-discuss] hierarchical version of ttk.combobox Message-ID: Hi All, Is there some widget that can give me a hierarchical popup menu similar to ttk.combobox, but with each item opening a submenu? Mick From kw at codebykevin.com Mon Jul 23 03:31:14 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Sun, 22 Jul 2012 21:31:14 -0400 Subject: [Tkinter-discuss] hierarchical version of ttk.combobox In-Reply-To: References: Message-ID: <500CA962.8050704@codebykevin.com> On 7/22/12 9:22 PM, Michael O'Donnell wrote: > Hi All, > > Is there some widget that can give me a hierarchical popup menu > similar to ttk.combobox, but with each item opening a submenu? > > Mick > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > How about tk_popup()? http://effbot.org/zone/tkinter-popup-menu.htm --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From jgriscti at gmail.com Tue Jul 24 15:45:38 2012 From: jgriscti at gmail.com (Jane) Date: Tue, 24 Jul 2012 13:45:38 +0000 (UTC) Subject: [Tkinter-discuss] Toggle buttons References: <20120712113837.5241e55f@dino> Message-ID: Mark Summerfield qtrac.plus.com> writes: > > Hi, > > I want to create a toggle button, i.e., a button that when clicked goes > down (if it is up) and goes up (if it is down). > > One easy way to achieve this is to set the button's style to > "Toolbutton" (see self.toggle2). But unfortunately, that gets rid of the > button's relief so it looks out of place amongst other non-toggling > buttons. > > I solved if for Linux using a custom style (see self.toggle3). But this > doesn't work on Windows and I can't figure out how to solve it. > > Can anyone suggest a solution? > > Here's the code I've got: > > ############################################################ > import tkinter.ttk > > class Window(tkinter.ttk.Frame): > > def __init__(self, master=None): > super().__init__(master) > self.toggle1 = tkinter.ttk.Button(text="Off", > command=lambda *args: self.toggle(self.toggle1)) > self.toggle1.pack(padx=5, pady=5) > self.toggle2 = tkinter.ttk.Button(text="Off", style="Toolbutton", > command=lambda *args: self.toggle(self.toggle2)) > self.toggle2.pack(padx=5, pady=5) > self.toggle3 = tkinter.ttk.Button(text="Off", > command=lambda *args: self.toggle(self.toggle3)) > self.toggle3.pack(padx=5, pady=5) > style = tkinter.ttk.Style() > style.configure("Toggle.TButton") > style.map("Toggle.TButton", relief=[("pressed", "sunken"), > ("selected", "sunken"), ("!selected", "raised")]) > self.toggle3.config(style="Toggle.TButton") > tkinter.ttk.Button(text="Quit", > command=self.master.destroy).pack(padx=5, pady=5) > self.pack() > > def toggle(self, button): > if button.instate(("!selected",)): > button.state(("selected",)) > button.config(text="On") > else: > button.state(("!selected",)) > button.config(text="Off") > > window = Window() > window.master.title("Toggle") > window.master.mainloop() > ############################################################ > > Thanks! > Hi ... Found that setting the ttk.Checkbutton style to 'TButton' forces it to appear as themed button; then, on selection, changing it to 'Toolbutton' gives it a 'sunken' appearance. Works ok under Windows 7. cb1 = ttk.Checkbutton(f, style='Demo.TButton', image=(self.noletters, 'selected', self.letters), command=lambda: self._cb_value_changed(cb1)) def _cb_value_changed(self, cb): # if a checkbutton is selected, use the 'Toolbutton' # style to make it appear 'sunken' if 'selected' in cb.state(): cb['style'] = 'Demo.Toolbutton' else: cb['style'] = 'Demo.TButton' From list at qtrac.plus.com Tue Jul 24 17:05:01 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Tue, 24 Jul 2012 16:05:01 +0100 Subject: [Tkinter-discuss] Toggle buttons In-Reply-To: References: <20120712113837.5241e55f@dino> Message-ID: <20120724160501.484be7f1@dino> Hi Jane, On Tue, 24 Jul 2012 13:45:38 +0000 (UTC) Jane wrote: > Mark Summerfield qtrac.plus.com> writes: > > > > > Hi, > > > > I want to create a toggle button, i.e., a button that when clicked goes > > down (if it is up) and goes up (if it is down). > > > > One easy way to achieve this is to set the button's style to > > "Toolbutton" (see self.toggle2). But unfortunately, that gets rid of > > the button's relief so it looks out of place amongst other non-toggling > > buttons. > > > > I solved if for Linux using a custom style (see self.toggle3). But this > > doesn't work on Windows and I can't figure out how to solve it. > > > > Can anyone suggest a solution? [snip] > Hi ... > > Found that setting the ttk.Checkbutton style to 'TButton' forces it to > appear as themed button; then, on selection, changing it to 'Toolbutton' > gives it a 'sunken' appearance. Works ok under Windows 7. > > cb1 = ttk.Checkbutton(f, style='Demo.TButton', > image=(self.noletters, 'selected', > self.letters), command=lambda: self._cb_value_changed(cb1)) > > def _cb_value_changed(self, cb): > # if a checkbutton is selected, use the 'Toolbutton' > # style to make it appear 'sunken' > if 'selected' in cb.state(): > cb['style'] = 'Demo.Toolbutton' > else: > cb['style'] = 'Demo.TButton' I tried your idea on Windows 7 & Linux (& a slightly simplified version which did the same). Yes, it correctly changes the appearance between raised and sunken: but in the sunken state the width of the button shrinks to fit the text -- and there's no width property for styled buttons:-( Here's the code: ############################################################ import tkinter.ttk class Window(tkinter.ttk.Frame): def __init__(self, master=None): super().__init__(master) self.toggle1 = tkinter.ttk.Button(self, text="Off (1)", command=lambda *args: self.toggle(self.toggle1, 1)) self.toggle1.pack(padx=5, pady=5) self.toggle2 = tkinter.ttk.Button(self, text="Off (2)", style="Toolbutton", command=lambda *args: self.toggle(self.toggle2, 2)) self.toggle2.pack(padx=5, pady=5) self.toggle3 = tkinter.ttk.Button(self, text="Off (3)", command=lambda *args: self.toggle(self.toggle3, 3)) self.toggle3.pack(padx=5, pady=5) style = tkinter.ttk.Style() style.configure("Toggle.TButton") style.map("Toggle.TButton", relief=[("pressed", "sunken"), ("selected", "sunken"), ("!selected", "raised")]) self.toggle3.config(style="Toggle.TButton") self.toggle4 = tkinter.ttk.Checkbutton(self, style="Toggle.TButton", text="Off (4)", command=lambda *args: self.toggle_style(self.toggle4, 4)) self.toggle4.pack(padx=5, pady=5) tkinter.ttk.Button(self, text="Quit", command=self.master.destroy).pack(padx=5, pady=5) self.pack() def toggle_style(self, button, number): if button.instate(("selected",)): button.config(text="Off ({})".format(number)) button.config(style="Toolbutton") else: button.config(text="On ({})".format(number)) button.config(style="Toggle.TButton") def toggle(self, button, number): if button.instate(("!selected",)): button.state(("selected",)) button.config(text="On ({})".format(number)) else: button.state(("!selected",)) button.config(text="Off ({})".format(number)) window = Window() window.master.title("Toggle") window.master.mainloop() ############################################################ -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Programming in Go" - ISBN 0321774639 http://www.qtrac.eu/gobook.html From jgriscti at gmail.com Tue Jul 24 20:50:36 2012 From: jgriscti at gmail.com (Jane Griscti) Date: Tue, 24 Jul 2012 14:50:36 -0400 Subject: [Tkinter-discuss] Fwd: Toggle buttons In-Reply-To: References: <20120712113837.5241e55f@dino> <20120724160501.484be7f1@dino> Message-ID: ---------- Forwarded message ---------- From: Jane Griscti Date: Tue, Jul 24, 2012 at 1:37 PM Subject: Re: [Tkinter-discuss] Toggle buttons To: Mark Summerfield On Tue, Jul 24, 2012 at 11:05 AM, Mark Summerfield wrote: > Hi Jane, > > On Tue, 24 Jul 2012 13:45:38 +0000 (UTC) > Jane wrote: > > Mark Summerfield qtrac.plus.com> writes: > > > > > > > > Hi, > > > > > > I want to create a toggle button, i.e., a button that when clicked goes > > > down (if it is up) and goes up (if it is down). > > > > > > One easy way to achieve this is to set the button's style to > > > "Toolbutton" (see self.toggle2). But unfortunately, that gets rid of > > > the button's relief so it looks out of place amongst other non-toggling > > > buttons. > > > > > > I solved if for Linux using a custom style (see self.toggle3). But this > > > doesn't work on Windows and I can't figure out how to solve it. > > > > > > Can anyone suggest a solution? > [snip] > > > Hi ... > > > > Found that setting the ttk.Checkbutton style to 'TButton' forces it to > > appear as themed button; then, on selection, changing it to 'Toolbutton' > > gives it a 'sunken' appearance. Works ok under Windows 7. > > > > cb1 = ttk.Checkbutton(f, style='Demo.TButton', > > image=(self.noletters, 'selected', > > self.letters), command=lambda: self._cb_value_changed(cb1)) > > > > def _cb_value_changed(self, cb): > > # if a checkbutton is selected, use the 'Toolbutton' > > # style to make it appear 'sunken' > > if 'selected' in cb.state(): > > cb['style'] = 'Demo.Toolbutton' > > else: > > cb['style'] = 'Demo.TButton' > > I tried your idea on Windows 7 & Linux (& a slightly simplified version > which did the same). Yes, it correctly changes the appearance between > raised and sunken: but in the sunken state the width of the button > shrinks to fit the text -- and there's no width property for styled > buttons:-( > > Here's the code: > > ############################################################ > import tkinter.ttk > > class Window(tkinter.ttk.Frame): > > def __init__(self, master=None): > super().__init__(master) > self.toggle1 = tkinter.ttk.Button(self, text="Off (1)", > command=lambda *args: self.toggle(self.toggle1, 1)) > self.toggle1.pack(padx=5, pady=5) > self.toggle2 = tkinter.ttk.Button(self, text="Off (2)", > style="Toolbutton", > command=lambda *args: self.toggle(self.toggle2, 2)) > self.toggle2.pack(padx=5, pady=5) > self.toggle3 = tkinter.ttk.Button(self, text="Off (3)", > command=lambda *args: self.toggle(self.toggle3, 3)) > self.toggle3.pack(padx=5, pady=5) > style = tkinter.ttk.Style() > style.configure("Toggle.TButton") > style.map("Toggle.TButton", relief=[("pressed", "sunken"), > ("selected", "sunken"), ("!selected", "raised")]) > self.toggle3.config(style="Toggle.TButton") > self.toggle4 = tkinter.ttk.Checkbutton(self, > style="Toggle.TButton", text="Off (4)", > command=lambda *args: self.toggle_style(self.toggle4, 4)) > self.toggle4.pack(padx=5, pady=5) > tkinter.ttk.Button(self, text="Quit", > command=self.master.destroy).pack(padx=5, pady=5) > self.pack() > > def toggle_style(self, button, number): > if button.instate(("selected",)): > button.config(text="Off ({})".format(number)) > button.config(style="Toolbutton") > else: > button.config(text="On ({})".format(number)) > button.config(style="Toggle.TButton") > > def toggle(self, button, number): > if button.instate(("!selected",)): > button.state(("selected",)) > button.config(text="On ({})".format(number)) > else: > button.state(("!selected",)) > button.config(text="Off ({})".format(number)) > > window = Window() > window.master.title("Toggle") > window.master.mainloop() > ############################################################ > > > -- > Mark Summerfield, Qtrac Ltd, www.qtrac.eu > C++, Python, Qt, PyQt - training and consultancy > "Programming in Go" - ISBN 0321774639 > http://www.qtrac.eu/gobook.html > Hi Mark ... there is a width value for ttk.Checkbutton. I was able to get it work with the code below. I just forced a width of 11 pixels (tried to use the winfo_reqwidth() of another button to get the right size but it returns 76 for some reason ... there must be a way to get a decent size??) tkinter.ttk.Style().configure('Toggle.Toolbutton', anchor='center') self.toggle4 = tkinter.ttk.Checkbutton(self, style='Toggle.TButton', text="Off (4)", width=-11, command=lambda *args: self.toggle_style(self.toggle4, 4)) self.toggle4.pack(padx=5, pady=5) def toggle_style(self, button, number): if button.instate(("selected",)): button.config(text="Off ({})".format(number)) button.config(style="Toggle.Toolbutton") else: button.config(text="On ({})".format(number)) button.config(style="Toggle.TButton") Jane PS Apologies, thought I had sent this to the list -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Tue Jul 24 21:17:12 2012 From: klappnase at web.de (Michael Lange) Date: Tue, 24 Jul 2012 21:17:12 +0200 Subject: [Tkinter-discuss] Fwd: Toggle buttons In-Reply-To: References: <20120712113837.5241e55f@dino> <20120724160501.484be7f1@dino> Message-ID: <20120724211712.e3c5f0be.klappnase@web.de> Hi, Thus spoketh Jane Griscti unto us on Tue, 24 Jul 2012 14:50:36 -0400: > I was able to get it work with the code below. I just forced a width > of 11 pixels (tried to use the winfo_reqwidth() of another button to > get the right size but it returns 76 for some reason ... there must be > a way to get a decent size??) Sounds like a tiny checkbutton ;) I suspect that the "11" refers to character units rather than pixels and the "76" looks like a reasonable pixel size for a button. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. The sooner our happiness together begins, the longer it will last. -- Miramanee, "The Paradise Syndrome", stardate 4842.6 From list at qtrac.plus.com Wed Jul 25 09:03:43 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Wed, 25 Jul 2012 08:03:43 +0100 Subject: [Tkinter-discuss] Fwd: Toggle buttons In-Reply-To: References: <20120712113837.5241e55f@dino> <20120724160501.484be7f1@dino> Message-ID: <20120725080343.23aa92e6@dino> Hi Jane, On Tue, 24 Jul 2012 14:50:36 -0400 Jane Griscti wrote: [snip] > Hi Mark ... there is a width value for ttk.Checkbutton. > > I was able to get it work with the code below. I just forced a width of > 11 pixels (tried to use the winfo_reqwidth() of another button to get the > right size but it returns 76 for some reason ... there must be a way to > get a decent size??) > > > tkinter.ttk.Style().configure('Toggle.Toolbutton', > anchor='center') self.toggle4 = tkinter.ttk.Checkbutton(self, > style='Toggle.TButton', text="Off (4)", width=-11, > command=lambda *args: self.toggle_style(self.toggle4, 4)) > self.toggle4.pack(padx=5, pady=5) > > def toggle_style(self, button, number): > if button.instate(("selected",)): > button.config(text="Off ({})".format(number)) > button.config(style="Toggle.Toolbutton") > else: > button.config(text="On ({})".format(number)) > button.config(style="Toggle.TButton") > > Jane You're right about the width option (I was thinking of ttk.Button). However, I've found two problems with this approach: (1) button widths differ per platform (so on Windows 7 I need -11 and on Linux -9; and this may vary with DPI or other factors, so setting width may not be a good idea) (2) the text is centered (like the other buttons) when in TButton style; but is left aligned in Toolbutton style. And there doesn't seem to be a justify option for ttk.Checkbuttons. So, for now, I'm using the style approach for Linux since it works perfectly there, and for Windows and Mac OS X I'm adding an image to the button with one image for selected and one for deselected. Thanks! -- Mark Summerfield, Qtrac Ltd, www.qtrac.eu C++, Python, Qt, PyQt - training and consultancy "Programming in Go" - ISBN 0321774639 http://www.qtrac.eu/gobook.html