Mailing List Archive

tkinter docs?
I am looking for complete tkinter docs
specifically I want to make a text area, or Pmw.SrolledText area be a
certain dimension, however generic instructions how to get all tkinter/pmw
widgets to be sized as I desire, would be appreciated

Even more preferable would be complete Tkinter documentation (including
height and width setting/requests), because I would much rather have to
tools to stop bothering all you fine folks.

email replies are acceptable, although I do check the newsgroup at least daily

Thanks in advance
--
---------------------
If barbie is so popular why do you have to buy all her friends?
tkinter docs? [ In reply to ]
narf@golden.net wrote:
>
> I am looking for complete tkinter docs

For documentation on Tkinter, you should check out the python home page
for a list of links: http://www.python.org/topics/tkinter

There are several good reference sites listed on that page. For some of
the Tk documentation, it helps if you know Tcl (enough of which I
learned to make sense of the docs). I also recommend _Practical
Programming in Tcl and Tk_ by Brent Welch if you are looking for
hardcopy. It has some pretty good coverage of Tk as a whole.

> specifically I want to make a text area, or Pmw.SrolledText area be a
> certain dimension, however generic instructions how to get all tkinter/pmw
> widgets to be sized as I desire, would be appreciated

For a straight Tkinter text widget, use the width and height attributes
to control the dimensions. The units are characters and lines
respectively, and the values can be set when the widget is created or
via a call to the configure method.

For a Pmw.ScrolledText widget, you want to specify the width or height
of the 'text' component of the composite widget. To do that, you can
set the attribute of the text component during creation or through a
configure call to the composite with the syntax:

widget.configure(<component>_<attribute>=<value>)

For example:

myScrolledText.configure(text_height=15)

will give you a 15 line high scrolled text area. This syntax becomes
*really* fun when you start creating composite widgets made up of other
composite widgets.

I haven't tried it, but you might also be able to configure the
component widget directly with a call like:

myScrolledText.component('text').configure(height=15)

Although even if that worked it would introduce extra complexity to your
code. I don't believe it would affect efficiency, just readability.

Good luck,
Doug
tkinter docs? [ In reply to ]
On 11 May, Doug Hellmann wrote:
> For a Pmw.ScrolledText widget, you want to specify the width or height
> of the 'text' component of the composite widget. To do that, you can
> set the attribute of the text component during creation or through a
> configure call to the composite with the syntax:
>
> widget.configure(<component>_<attribute>=<value>)
>
> For example:
>
> myScrolledText.configure(text_height=15)
>
> will give you a 15 line high scrolled text area. This syntax becomes
> *really* fun when you start creating composite widgets made up of other
> composite widgets.

Pmw has aliases which simplifies access to sub-sub-sub-components.

For example, a
Pmw.ComboBoxDialog megawidget contains a
Pmw.ComboBox megawidget which in turn contains a
Pmw.ScrolledListBox megawidget which contains a
Tkinter.Listbox widget.

You can configure the Tkinter.Listbox widget using any of the
following:

dlg = Pmw.ComboBoxDialog()

# Using chained component() methods:
dlg.component('combobox').component('scrolledlist').\
component('listbox').configure(height = 15)

# Using full component name:
dlg.configure(combobox_scrolledlist_listbox_height = 15)

# Using component alias:
dlg.configure(listbox_height = 15)

The aliases for each megawidget are given in the Pmw manual pages.

Pmw:
http://www.dscpl.com.au/pmw/

--
Greg McFarlane
INMS Telstra Australia (gregm@iname.com)
tkinter docs? [ In reply to ]
Greg McFarlane wrote:
>
> # Using component alias:
> dlg.configure(listbox_height = 15)
>
> The aliases for each megawidget are given in the Pmw manual pages.

Ah ha! That's what the aliases are for. I noticed those on one of my
first trips through the docs, but since it isn't something I use that
often I hadn't read it again more carefully. The intuitive solution of
combining the names worked in the case where I needed it, so I didn't
search for an easier solution.

Thanks,
Doug
Re: Tkinter docs? [ In reply to ]
On 2023-05-24, Rob Cliffe via Python-list <python-list@python.org> wrote:
> I have recently started converting a large project to tkinter, starting
> with zero knowledge of tkinter.  (You are free to think: BAD IDEA. ????)

Well, you could be translating them to Tcl/Tk -- so on the scale of
bad ideas, your's barely registers.

> I am well aware that adopting a new tool always involves a learning
> curve, and that one is prone to think that things are more difficult
> than they are/should be, and to belly-ache about it, and that in a year
> from now I'll probably wonder what I'm fussing about.
> Nonetheless ISTM that there is a particular problem with tkinter:
>
> There doesn't seem to be any decent documentation for it anywhere.

Back in the day, the Grayson book was the definitive reference:

https://www.amazon.com/Python-Tkinter-Programming-John-Grayson/dp/1884777813/

It's 20+ years old now, so the version of Python it uses is pretty
ancient, and I presume Tk has also changed a bit over the years, so...

There are a couple recent books, but I haven't looked at them:

https://www.amazon.com/Modern-Tkinter-Busy-Python-Developers-dp-1999149564/dp/1999149564/

https://www.amazon.com/Python-GUI-Programming-Tkinter-user-friendly/dp/1801815925/

--
Grant
--
https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter docs? [ In reply to ]
On 5/23/23 21:18, Rob Cliffe wrote:

> Comments, anyone?
> Better yet (holds breath ...) can anyone point me towards some decent
> tkinter documentation?

The variables are slightly more integrated when using tcl/tk directly,
python has to have the object so you can track/use them easier. And the
variables are more of what is intended to track a widgets purpose, vs
state stuff that is more the state of the displaying of the widget.

occasionally giving tcl/tk a try directly helps, and using the official
tcl/tk docs in addition to a couple other decent docs below.

https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/index.html
https://tkdocs.com/tutorial/styles.html

https://www.tcl.tk/man/tcl8.6/
https://www.tcl.tk/man/tcl8.6/TkCmd/contents.html
https://www.tcl.tk/man/tcl8.6/TkLib/contents.html

(this used to be some documentation that I only discovered existed
recently, but most of it doesn't load and I don't know that anyone
backed it up for rehosting..)
https://web.archive.org/web/20200227170827/http://effbot.org/tkinterbook

tk is decent for what it can do, (and it could do potentially more if
you had a lifetime to dedicate to it, lol) and it's reasonably stable
and not being perpetually hacked about and broken like gtk.

A couple additional pointers in case these haven't been figured out yet:
Running it interactively and using tab complete helps.
If you are running an app you can comment out the mytk.mainloop()
statement then run python -i yourtk.py to give you access to all widgets
live.
For navigating them, just come up with a widget naming convention that
works for you in a similar vein to how tk does (like .frame.frame.label
to start),
i.e.
main = tk.Tk()
main.frame = tk.Frame()
That way if you have anchored your widgets to something at the root
level you can navigate down to whatever you are looking for easily. (you
can also use winfo_children() iteratively to travel the way tcl
structures them, but that is tedious).
--
https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter docs? [ In reply to ]
On Wed, 24 May 2023 at 13:11, Rob Cliffe via Python-list
<python-list@python.org> wrote:
>
> I have recently started converting a large project to tkinter, starting
> with zero knowledge of tkinter. (You are free to think: BAD IDEA. ????)
> I am well aware that adopting a new tool always involves a learning
> curve, and that one is prone to think that things are more difficult
> than they are/should be, and to belly-ache about it, and that in a year
> from now I'll probably wonder what I'm fussing about.

Yes, I do think this is a bad idea, though not an abysmal one. I would
recommend first playing with tkinter in a dedicated UI-only project
before converting the main project to it. Your code in the scratch
project can be as messy as it likes, and then you learn from it before
tackling the big one :)

But your concerns about tkinter's documentation are, sadly,
well-founded. Since it's this weird system of thin wrappers around
Tcl/Tk, a lot of things are basically just "go read the Tk docs".
There are a few key concepts you'll need to get your head around, and
I can't go into details because I never truly got *my* head around
them... but mostly, the way that variables are used and what happens
when events fire.

Good luck with it. I'll be frank, building a GUI can be pretty hard...
I'm still unsure whether the best way is to use something like
tkinter, or to build a web app, pop up a browser window, and establish
a websocket to communicate between your JavaScript front end and your
Python back end. Yeah, that's how bad GUI building can be sometimes -
it is potentially *easier* to build two halves of your app in two
different languages than to make your GUI work the way you want it.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter docs? [ In reply to ]
Am 24.05.23 um 03:18 schrieb Rob Cliffe:
> I have recently started converting a large project to tkinter, starting
> with zero knowledge of tkinter.  (You are free to think: BAD IDEA. ????)

Welcome to the awesome world of GUI development.

>     I was writing a subclass of the Checkbutton class (tkinter's name
> for what I call a checkbox).  I needed to be able to (1) set (2) clear
> (3) interrogate the checked state.  This is easy to do if you associate
> a "variable" with each Checkbutton instance, as seems to be usual
> tkinter practice.  ("variable" is not a variable in the usual sense, but
> an object provided by tkinter that is linked to a GUI object (such as a
> Checkbutton), so that when the GUI object changes, the value of the
> "variable" changes, and vice versa.) However, I decided that I wanted to
> dispense with the variable, if possible.

As you found out the hard way, it is possible, but then you dive into
the internals of how the widgets work - usually you don't want to know
that. Also, this bit differs between Tk and Ttk widgets.


> [...] lengthe description of Checkbutton internals


In GUI programming, you will meet a bag of concepts that you haven't
seen in sequential programming before. To make it worse, every GUI
toolkit brings its own new set of concepts to the table. Maybe it is
helpful to work through a Tk tutorial first. This is a good one:

http://tkdocs.com/tutorial/index.html

Similarly to the tutorial I would suggest to stick with the ttk widgets.
Those are an "update" (> 10 years ago) to the tk widgets and are
supposed to provide sensible defaults matching the users experience with
native GUI elements. There are only 3 widgets where you must use a Tk
widget, this is Text (for multiline formatted text entry), Canvas (for
2D drawings), and Toplevel (for new windows/ popups etc.)

Christian

--
https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter docs? [ In reply to ]
On 24May2023 02:18, Rob Cliffe <rob.cliffe@btinternet.com> wrote:
>    There doesn't seem to be any decent documentation for it anywhere.

Already mentioned in the replies, I use this:
https://tkdocs.com/shipman/index.html
quite a lot.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter docs? [ In reply to ]
Thanks to everyone who replied.  All replies were constructive, none
were telling me to stop belly-aching.
I forgot/omitted to state that it was I who wrote the original project
(in a completely different language), making the task of re-writing it
much less formidable.  And meaning that I am familiar with the general
concepts of building a GUI.  Still, it will be a lot of work.

Grant, I may well buy one of the books you suggested.
I find the topic of themes and styles the hardest one to get my head
around (if anyone knows a good introduction that would be fantastic). 
All the other stuff is OK provided I can find something on the net to
give me the necessary information, which so far I usually can.

Christian, I am adopting your suggestion of using ttk widgets, except
for Button objects, because
    The colour of tk.Button objects can be set directly (bg=... fg=...)
    On my platform (Windows10) the shadowing of tk.Button objects is
more conspicuous (without using styles or whatever).

Best wishes
Rob Cliffe

--
https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter docs? [ In reply to ]
On 2023-05-26, Rob Cliffe via Python-list <python-list@python.org> wrote:

> Grant, I may well buy one of the books you suggested.

I haven't had look at either of the newer books, but I got a lot of
good out of the Grayson book (20 years ago). I also had a Tcl/Tk book
that I found useful even when usng tkinter, but it's even older than
the Grayson one...
--
https://mail.python.org/mailman/listinfo/python-list