Re: [Tkinter-discuss] Get menu index from label

2023-04-14 Thread Bryan Oakley
You can use the label string as the index. Or more accurately, a pattern that matches an element. Once tkinter finds an item that matches the pattern, that item will be used. For example, "Save*" might match both "Save" and "Save As...", but whichever one comes first in the menu is the one that wil

Re: [Tkinter-discuss] new location for John Shipman's Tkinter reference manual

2020-08-28 Thread Bryan Oakley
This is an excellent idea. Thanks, Mark! On Fri, Aug 28, 2020 at 3:08 PM Mark Roseman wrote: > As many of you know, John had created a substantial and valuable reference > to Tkinter prior to his retirement from New Mexico Tech in 2013. He passed > away in 2017. > > While it hadn’t been updated,

Re: [Tkinter-discuss] tk bug in wait_visibility?

2020-02-14 Thread Bryan Oakley
wait_visibility waits for a *change in the visibility,* it doesn't just wait for the window to be visible. If it's already visible, wait_visibility will wait for it to be invisible. The geometry method doesn't affect the visibility state (unless you move the window off-screen perhaps) which is why

Re: [Tkinter-discuss] Tkinter to Qt-whatever

2019-11-14 Thread Bryan Oakley
tkdocs.com is a real gem! You've done a masterful job of explaining tk and tkinter, and it is by far the best documentation on how to use and configure ttk. In fact, I was visiting there today to re-remind myself about how ttk layouts work. On Wed, Nov 13, 2019 at 8:20 PM Mark Roseman wrote: > H

Re: [Tkinter-discuss] Scrollbar for thumbnails

2019-01-11 Thread Bryan Oakley
The canvas can only scroll things added to the canvas with the create_* functions (create_image, create_window, create_line, etc). You cannot add widgets to the canvas with pack, place, or grid, and then be able to scroll them. On Fri, Jan 11, 2019 at 1:15 PM Mario St-Gelais wrote: > I am havin

Re: [Tkinter-discuss] How to eliminate flickers when swapping frames?

2018-03-27 Thread Bryan Oakley
I don't see any flicker when I run that. On Tue, Mar 27, 2018 at 2:57 PM, Nam Nguyen via Tkinter-discuss < tkinter-discuss@python.org> wrote: > A simple reprod code: > > import tkinter as tk > from tkinter import font > > > root = tk.Tk() > root.minsize(1280, 800) > root.bind('', lambda _: root.q

Re: [Tkinter-discuss] Revisiting the adage of GUI thread

2018-03-26 Thread Bryan Oakley
I don't know with absolute certainty, but I would say that getting/setting variables is considered a "GUI action". Earlier I quoted Donal Fellows as saying "you must make sure that you only ever run Tcl commands or Tkinter operations from a single thread". Getting or setting a variable requires run

Re: [Tkinter-discuss] Revisiting the adage of GUI thread

2018-03-26 Thread Bryan Oakley
I think that part of the problem arises due to the fact that the tk library used by tkinter might not have been compiled with thread support. It's an explicit option required during the compile stage (--enable-threads). If you don't have a tk library compiled with thread support, then modifying tki

Re: [Tkinter-discuss] configure command

2018-03-07 Thread Bryan Oakley
> > For the last time, what is the parameter's name that accepts option's name > as a string: The tk documentation calls this "option". In python it doesn't have a literal name. If you need to refer to it in documentation you could use "argument" or "the only argument" or "the first positional a

Re: [Tkinter-discuss] Listbox size

2018-02-13 Thread Bryan Oakley
If your actual goal is to scroll the listbox so that an item is centered, you can first scroll the item as far as possible and then call the "see" method. For example, if the result is in the first half of the items, scroll all the way down (listbox.yview("end")). If it's in the second half, scroll

Re: [Tkinter-discuss] Listbox size

2018-02-13 Thread Bryan Oakley
The actual height of any widget can be obtained with the winfo_height method. It returns the value in pixels. To get the height in number of lines you'll have to compute the height of your font and do a little math. On Tue, Feb 13, 2018 at 12:11 PM, Bob van der Poel wrote: > Is there a way to

Re: [Tkinter-discuss] Simulating keystrokes in a tkinter unit test

2018-02-01 Thread Bryan Oakley
You might need to also generate a event and/or move the mouse over the widget with the warp option (widget.event_generate(..., warp=True), but you may need to also specify an x and y coordinate. I don't remember). I think some widgets check to see if they have focus, and will ignore keyboard event

Re: [Tkinter-discuss] Mapping Tcl's arguments to Python's arguments

2018-01-04 Thread Bryan Oakley
You cannot generalize tcl arguments. The tcl syntax is exceptionally simple: every statement starts with a command, and every "word" after that is an argument. A "word" can be just that - a single word, or a collection of characters inside quotes. It is up to each individual command as to how it i

Re: [Tkinter-discuss] why from _tkinter import * ? why the underscore

2018-01-01 Thread Bryan Oakley
_tkinter is the internal name of the C-based wrapper around the tcl interpreter. It has a leading underscore to highlight the fact that it's a "private" method that is part of the tkinter package. On Sat, Dec 30, 2017 at 7:50 PM, R wrote: > > whyfrom _tkinter import * ? > > > > why the

Re: [Tkinter-discuss] Tkinter option-value

2017-11-22 Thread Bryan Oakley
Are you asking a question, or just mentioning an observation. Personally I find the use of tkinter constants a bit silly. I see no point in using something like tkinter.END instead of "end". I always recommend that people learn to use the string form rather than the constant. On Wed, Nov 22, 201

Re: [Tkinter-discuss] Documentation

2017-10-18 Thread Bryan Oakley
No, that link does not point to an official resource. It is one of several independent sets of documentation. Unfortunately, the strategy for official documentation seems to be "use the tcl/tk documentation, and here's how to apply that to tkinter". The official, canonical tk.documentation (upon wh

Re: [Tkinter-discuss] pack(fill=Y) not working as expected

2017-08-07 Thread Bryan Oakley
On OSX, buttons will not grow vertically. That platform has strict requirements about the look of buttons. On Mon, Aug 7, 2017 at 4:25 AM, Beinan Li wrote: > I found that the problem applies to Button, but not Label. > > Using > > root = tk.Tk() > tk.Label(root, text="A", bg='green').pack(side=t

Re: [Tkinter-discuss] Add text to desktop

2016-05-25 Thread Bryan Oakley
There is no way to do what you want with tkinter. On Wed, May 25, 2016 at 10:56 AM, Dudi Goldenberg wrote: > Hello list, > > > > What would be the best way to add some text over the desktop background > image, with no window and no frame? > > > > Font, size and colors needs to be controlled, som

Re: [Tkinter-discuss] Tkinter multiple font sizes in same text input

2016-04-30 Thread Bryan Oakley
it is not possible to do this with an Entry widget, but you can create a one-line Text widget and use the text widget's ability to change the attributes of each character with tags. On Fri, Apr 29, 2016 at 9:31 AM, Stewart Baskin wrote: > Hello, > > > > Thank you in advance for your assistance w

Re: [Tkinter-discuss] Centering grid inside a frame

2015-06-25 Thread Bryan Oakley
Use an empty row and column surrounding your other widgets, and give those rows and columns a weight. That is, leave row and column 0 empty, and the row and column below and to the right of all the other widgets empty. With a non-zero weight, and with the non-empty rows/columns with a default weigh

Re: [Tkinter-discuss] Text folding of text

2015-01-22 Thread Bryan Oakley
Yes, it is possible, though you have to do a lot of the work yourself. You can actually intercept the low level text insertions and deletions that happen as a result of the built-in bindings, and allow or reject the insertions based on whatever criteria you want. You can, for example, check the ta

Re: [Tkinter-discuss] Combining events?

2014-07-19 Thread Bryan Oakley
Have you considered creating a subclass of entry? Then your code is simply: LEnt = CustomEntry(stuff stuff stuff) You can then put all the bind magic in the constructor of CustomEntry. On Sat, Jul 19, 2014 at 12:21 PM, Bob Greschke wrote: > > On 2014-07-19, at 05:21, Michael Lange wrote

Re: [Tkinter-discuss] How to enable/disable a menu?

2014-05-14 Thread Bryan Oakley
The "state" attribute. Here's a working example: import Tkinter as tk root = tk.Tk() menubar = tk.Menu(root) root.configure(menu=menubar) exampleMenu = tk.Menu(root) exampleMenu.add_command(label="One") exampleMenu.add_command(label="Two") exampleMenu.add_command(label="Three") menubar.add_casc

Re: [Tkinter-discuss] How to enable/disable a menu?

2014-05-14 Thread Bryan Oakley
You can disable the button or menu item the menu is associated with, and that will disable the whole menu. --bryan > On May 13, 2014, at 1:51 PM, Alan Gauld wrote: > > I have an app with a tabbed notebook. I want to > only enable one of the main menus when the appropriate > tab is selected.

Re: [Tkinter-discuss] Binding a List to a ScrollBar

2014-01-16 Thread Bryan Oakley
A listbox can only scroll text. So, to display a colored word you would use the "itemconfig" method to change the background and foreground of each element individually. For example: for index, color in enumerate(colors): listbox.insert("end", color) listbox.itemco

Re: [Tkinter-discuss] [Python-Dev] Binding problem

2014-01-15 Thread Bryan Oakley
When you do this: butCol.ks2=Entry(...).grid(...) you are setting butCol to None, because .grid(...) returns None. Separate the widget creation and widget layout into two distinct steps so that butCol.ks2 has an actual value: butCol.ks2 = Entry(...) butCol.ks2.grid(...) This should then al

Re: [Tkinter-discuss] Getting an Entry field to stretch

2013-07-02 Thread Bryan Oakley
This problem requires that you do two things: a) cause the width of the inner frame to resize when the canvas resizes b) make sure the widgets inside the inner frame resize when the inner frame resizes. For a), you need to do a binding on the event of the canvas. In the callback for that binding

Re: [Tkinter-discuss] question on winfo_height

2013-04-10 Thread Bryan Oakley
winfo_height returns the actual, absolute height of the window. It's not relative to anything. The reason the value is 1 is because the frame has yet to be displayed on the screen. It is the actual updating of the screen that gives a widget its dimensions, since that depends on the size of the con

Re: [Tkinter-discuss] class_ attribute on ttk widgets

2013-03-31 Thread Bryan Oakley
It is expected behavior. The built-in key and mouse bindings are bound to the class, so if you change the class of a widget it will no longer have these bindings. Changing the class is mostly useful if you want to create a completely different set of bindings for a widget. --bryan On Mar 31

Re: [Tkinter-discuss] confused on grid positioning vs. imports

2013-03-08 Thread Bryan Oakley
On Fri, Mar 8, 2013 at 10:18 AM, Monte Milanuk wrote: > Bryan Oakley gmail.com> writes: > >> My advice: >> >> Always do it this way: >> >> import Tkinter as tk >> import ttk >> >> There! Now there's no global namespa

Re: [Tkinter-discuss] confused on grid positioning vs. imports

2013-03-08 Thread Bryan Oakley
On Thu, Mar 7, 2013 at 11:38 PM, Monte Milanuk wrote: > So... I've been tinkering with python and Tkinter and ttk a bit lately, and > because I've been using pylint which complains a lot if I do a wildcard > import like I see in many (most?) Tkinter tutorials i.e. > > from Tkinter import * > from

Re: [Tkinter-discuss] StringVar() .trace(), .trace_vdelete() use

2013-03-06 Thread Bryan Oakley
If you're doing this for input validation you should consider using the built-in validation features of the entry widget instead of using a trace. Here's a description of how to use it: http://stackoverflow.com/a/4140988/7432 On Wed, Mar 6, 2013 at 6:49 PM, Bob Greschke wrote: > Hi! > > I'm mes

Re: [Tkinter-discuss] loop delay

2012-10-22 Thread Bryan Oakley
On Sun, Oct 21, 2012 at 5:31 PM, Paul Simon wrote: > I' m a novice python programmer and now starting to learn tkinter for a > front and db back end to replace an application written MS Access/VBA. The > following program doesn't work as I expected as data is not written to the > text box until t

Re: [Tkinter-discuss] FocusOut not working as expected - tix broken?

2012-10-11 Thread Bryan Oakley
On Thu, Oct 11, 2012 at 12:19 PM, Michael Lange wrote: > I am not sure if I understand correctly what you are trying to achieve; > in one my programs there is a window with a couple of keyboard bindings > for this and that, there I simply put all the bindings into one method > like this: > > d

Re: [Tkinter-discuss] FocusOut not working as expected - tix broken?

2012-10-11 Thread Bryan Oakley
On Thu, Oct 11, 2012 at 11:20 AM, wrote: > Sorry, to have been unclear here. > My main interest is capturing all keyboard input > with these lines: > -- > > def on_key(event): > print('key') > > f.bind('', on_key) There are better ways to capture all keyboard inpu

Re: [Tkinter-discuss] [Tutor] displaying an image

2012-10-05 Thread Bryan Oakley
On Fri, Oct 5, 2012 at 1:10 PM, Matthew Ngaha wrote: > with no solution to my problem after 2 days of pulling my hair out:( i > realize that some libraries are best for the Python version they > support the most. Sadly most tkinter users use version 2 unlike me, so > im pretty much on my own as th

Re: [Tkinter-discuss] How to insert a string into a Text using Button

2012-06-01 Thread Bryan Oakley
On Fri, Jun 1, 2012 at 3:50 PM, Alexander Matyukhin < alex.matyuk...@yandex.ru> wrote: > Hello to all! I have a simple code, which use tkinter. > It has a Text widget and two Buttons. First Button > must insert string into text. But it dont do it. > The string is inserted into text after start and

Re: [Tkinter-discuss] How to prevent a selection when double-clicking?

2012-05-19 Thread Bryan Oakley
On Sat, May 19, 2012 at 12:42 AM, Juha Salo wrote: > Hi! > > Is there a way to get rid of the selection (blue area in the window) after > double-clicking on a Text widget? I use Vista and Python 3.2.3. I have the > following example: > > The selection happens on a single click; are you wanting to

Re: [Tkinter-discuss] Which virtual event have I received ?

2012-05-09 Thread Bryan Oakley
On Wed, May 9, 2012 at 6:07 AM, hamiljf wrote: > I want to be able to process more than one event type in an event handler > (I > know that there may be other ways of doing this, and I might well use them) > Now 'real' events are distinguished by event.type having a numeric value > listed all ove

Re: [Tkinter-discuss] [REQ] Tkinter programmer

2012-03-04 Thread Bryan Oakley
On Sun, Mar 4, 2012 at 11:51 AM, fresher wrote: > the first task is to build working calculator like this: > > http://python.6.n6.nabble.com/file/n4545517/skaiciavke.png > > later Ill have more tasks to build forms like this > > http://python.6.n6.nabble.com/file/n4545517/MLDataAnalyzer5.png > >

Re: [Tkinter-discuss] Tk*Font question

2012-02-29 Thread Bryan Oakley
On Wednesday, February 29, 2012, Bob Greschke wrote: > What's the correct way to change the font size? The "Change" button isn't > doing what I thought it would. The font changes size, but turns into some > proportional font. I'm kinda new (1 day) to using TkFixedFont and its > friends. I'm us

Re: [Tkinter-discuss] LabelFrame question: why do options change when importing from tkFileDialog?

2012-02-28 Thread Bryan Oakley
On Tue, Feb 28, 2012 at 1:22 PM, Lynn Oliver wrote: > I've discovered that 'bd=4' and 'font=...' both work if I import: > from tkFileDialog import askopenfilename, asksaveasfilename, askdirectory > from Tkinter import * > import tkFont > from ttk import * > > And they both fail if I import only: >

Re: [Tkinter-discuss] Tkinter and Alt bindings

2012-02-09 Thread Bryan Oakley
On Feb 9, 2012, at 2:04 PM, Michael Lange wrote: > > The default bindings are defined in entry.tcl, the relevant part looks > like: > > # Ignore all Alt, Meta, and Control keypresses unless explicitly bound. > # Otherwise, if a widget binding for one of these is defined, the > # class bind

Re: [Tkinter-discuss] Tkinter and Alt bindings

2012-02-09 Thread Bryan Oakley
On Thursday, February 9, 2012, Russell Adams wrote: > On Thu, Feb 09, 2012 at 11:22:47AM +0100, Michael Lange wrote: >> Hi, >> >> ## >> entry .e >> grid .e -column 0 -row 0 >> bind . {puts "Alt-s pressed"} >> focus .e >> # >> >> If you store this as test.tcl and then run it with $

Re: [Tkinter-discuss] Tkinter and Alt bindings

2012-02-08 Thread Bryan Oakley
On Wed, Feb 8, 2012 at 4:56 AM, Michael Lange wrote: > I cannot reproduce this here (debian squeeze with IceWM) either, the > return "break" isn't even necessary. I don't know why the original poster reports that the bindings sometimes fire. My guess is that it's related to keyboard focus -- may

[Tkinter-discuss] why tkinter hangs on windows with tcl server socket?

2011-12-06 Thread Bryan Oakley
I’m running the following program on Windows, and when I close the app by clicking on the window manage close button the app hangs. Obviously this isn’t my real code, but I can’t explain why the code is hanging, or what the workaround is to get it to not hang. Interestingly, the last line of code