Re: [Tkinter-discuss] Copy image to clipboard

2024-02-28 Thread Michael Lange via Tkinter-discuss
Hi again,

for the archives, here is a simplified and more generalized example of the
copy_image_to_clipboard() function that works without having to "detour"
with Canvas.postscript():

def copy_image_to_clipboard(filename):
image_buffer = io.BytesIO()

image = Image.open(filename)
image.save(image_buffer, format="PNG")
image_buffer.seek(0)

root.clipboard_clear()
root.clipboard_append(image_buffer.getvalue(), type="image/png")

This seems to work well here under X11.

Have a nice day,

Michael


On Wed, 28 Feb 2024 11:29:53 +0100
Michael Lange via Tkinter-discuss  wrote:

> On Thu, 22 Feb 2024 10:22:06 +
> Vasilis Vlachoudis  wrote:
>
> > Dear all,
> >
> > I am trying in X11 to copy an image to clipboard but with out success.
> (...)
>
> Hi Vasilis,
>
> sorry for the belated reply.
>
> This is tricky, I tried several suggestions found in the web to no
> avail. Finally for once an AI engine proved useful and provided me with
> an almost working solution which it seems I could fix with a little
> try-and-error :-)
>
> Here's the fixed AI code example:
>
> ##
>
> import tkinter as tk
> from PIL import Image, ImageTk
> import io
>
> root = tk.Tk()
> root.geometry("700x500")
> root.title("Copy a Picture from Tkinter Canvas to Clipboard")
> canvas = tk.Canvas(root, width=400, height=400)
> canvas.pack()
>
> image = Image.open("image.jpg")
> image_tk = ImageTk.PhotoImage(image)
> canvas.create_image(0, 0, anchor="nw", image=image_tk)
>
> def copy_image_to_clipboard():
> # Retrieve the image from the canvas
> canvas_image = canvas.postscript()
>
> # Create an in-memory file-like object
> image_buffer = io.BytesIO()
>
> # Save the canvas image to the buffer in PNG format
> image = Image.open(io.BytesIO(canvas_image.encode('utf-8')))
> image.save(image_buffer, format="PNG")
> image_buffer.seek(0)
>
> # Copy the image to the clipboard
> root.clipboard_clear()
> root.clipboard_append(image_buffer.getvalue(), type="image/png")
>
> copy_button = tk.Button(root, text="Copy Image",
> command=copy_image_to_clipboard) copy_button.pack()
>
> root.mainloop()
>
> ##
>
> The trick is apparently to change format="image/png" (suggested by our
> artificial friend) to type="image/png" in clipboard_append(). With
> format="image/png" when trying to paste the clipboard into lowriter I
> got only a mess of characters.
>
> Have a nice day,
>
> Michael
>
>
>
> ___
> Tkinter-discuss mailing list
> Tkinter-discuss@python.org
> https://mail.python.org/mailman/listinfo/tkinter-discuss



.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

You!  What PLANET is this!
-- McCoy, "The City on the Edge of Forever", stardate
3134.0
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Copy image to clipboard

2024-02-28 Thread Michael Lange via Tkinter-discuss
On Thu, 22 Feb 2024 10:22:06 +
Vasilis Vlachoudis  wrote:

> Dear all,
>
> I am trying in X11 to copy an image to clipboard but with out success.
(...)

Hi Vasilis,

sorry for the belated reply.

This is tricky, I tried several suggestions found in the web to no avail.
Finally for once an AI engine proved useful and provided me with an
almost working solution which it seems I could fix with a little
try-and-error :-)

Here's the fixed AI code example:

##

import tkinter as tk
from PIL import Image, ImageTk
import io

root = tk.Tk()
root.geometry("700x500")
root.title("Copy a Picture from Tkinter Canvas to Clipboard")
canvas = tk.Canvas(root, width=400, height=400)
canvas.pack()

image = Image.open("image.jpg")
image_tk = ImageTk.PhotoImage(image)
canvas.create_image(0, 0, anchor="nw", image=image_tk)

def copy_image_to_clipboard():
# Retrieve the image from the canvas
canvas_image = canvas.postscript()

# Create an in-memory file-like object
image_buffer = io.BytesIO()

# Save the canvas image to the buffer in PNG format
image = Image.open(io.BytesIO(canvas_image.encode('utf-8')))
image.save(image_buffer, format="PNG")
image_buffer.seek(0)

# Copy the image to the clipboard
root.clipboard_clear()
root.clipboard_append(image_buffer.getvalue(), type="image/png")

copy_button = tk.Button(root, text="Copy Image",
command=copy_image_to_clipboard) copy_button.pack()

root.mainloop()

##

The trick is apparently to change format="image/png" (suggested by our
artificial friend) to type="image/png" in clipboard_append(). With
format="image/png" when trying to paste the clipboard into lowriter I got
only a mess of characters.

Have a nice day,

Michael



___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Focus issue

2024-01-10 Thread Michael Lange via Tkinter-discuss
Hi,

On Wed, 10 Jan 2024 16:33:46 -0400
Cam Farnell  wrote:

> To answer my own question: the focus was being given to another widget
> after the code in question had executed.
>
> That said, I still don't understand why focus_set followed by
> update_idletasks followed by focus_get would return None, but tkinter
> something works in strange and mysterious ways.
>

I can only guess here, have you tried calling update_idletasks() (or even
update()) *before* calling focus_set() ?

Best regards,

Michael
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Navigation in menu with multiple columns

2023-09-23 Thread Michael Lange
Hi,

On Tue, 19 Sep 2023 09:34:34 +
Vasilis Vlachoudis  wrote:

> Using column breaks and sub-menus, makes navigation with the mouse
> almost impossible. e.g. with the code below
>
>   *   open the menu
>   *   hover the mouse over "one"
>   *   hover the mouse over "Item #40"
>   *to select the submenu
>   *   ... try to select in the new submenu "Item #40 : 2" with the mouse
>
> I cannot, since when I hover the mouse over the other items their
> respective submenu opens. I can only selected it with the keyboard.

you can avoid this by calling

root.option_add('*Menu.clickToFocus', '1')

immediately after creating the main Tk window. This doesn't seem to be
documented, you can find the option in menu.tcl though.
It is in the following code block in the Tk function ::tk::MenuMotion :


set mode [option get $menu clickToFocus ClickToFocus]
if {[string is false $mode]} {
set delay [expr {[$menu cget -type] eq "menubar" ? 0 : 50}]
if {[$menu type $index] eq "cascade"} {
set Priv(menuActivatedTimer) \
[after $delay [list $menu postcascade active]]
} else {
set Priv(menuDeactivatedTimer) \
[after $delay [list $menu postcascade none]]
}



So you see, if clickToFocus evaluates True, the call to postcascade does not 
occur.

Have a nice day,

Michael
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Navigation in menu with multiple columns

2023-09-16 Thread Michael Lange
Hi Vasilis,

On Fri, 15 Sep 2023 09:55:49 +
Vasilis Vlachoudis  wrote:

> Hi Michael,
>
> here is a snipped of a code and what I've managed up to now

thanks, I get your point now :-)

I toyed around with your example a bit and came up with a custom menu
class (see below; for testing I added a few useless separators and another
submenu to the demo code). It's far from being perfect, but at least the
keyboard navigation appears to work (It might require more thorough
testing, though. Separators appear to be especially tricky.). Just for the
fun of it I also added keybindings for the PageUp, PageDown, Home and End
keys, which I thought might come in handy when dealing with huge submenus.

Have a nice day,

Michael



import tkinter

class GriddedMenu(tkinter.Menu):
'''Menu with lots of menu items arranged in a grid.'''
# TODO: insert(), delete(), add_cascade(), add_checkbutton(),
# add_radiobutton(), add_separator(), configure()
def __init__(self, parent, numrows=20, **kw):
tkinter.Menu.__init__(self, parent, **kw)
self.numrows = numrows
self._curindex = -1
if self.type(0) == 'tearoff':
self._curindex = 0
self.bind("", self._on_key_right)
self.bind("", self._on_key_left)
self.bind("", self._on_key_pageup)
self.bind("", self._on_key_pagedown)
self.bind("", self._on_key_home)
self.bind("", self._on_key_end)

def add_cascade(self, **kw):
# FIXME: handle columnbreaks
tkinter.Menu.add_cascade(self, **kw)
self._curindex += 1

def add_command(self, **kw):
tkinter.Menu.add_command(self, **kw)
self._curindex += 1
if (self._curindex >= self.numrows) and \
(self._curindex % self.numrows == 0):
self.entryconfigure(self._curindex, columnbreak=1)

def add_separator(self, **kw):
# FIXME: handle columnbreaks
tkinter.Menu.add_separator(self, **kw)
self._curindex += 1

def _on_key_left(self, event):
index = self.index('active')
if index - self.numrows >= 0:
newindex = index - self.numrows
while (newindex >= 0) and (self.type(newindex) == 'separator'):
newindex -= self.numrows
if newindex >= 0:
self.activate(newindex)
return 'break'

def _on_key_right(self, event):
index = self.index('active')
end = self.index('end')
if index + self.numrows <= end:
newindex = index + self.numrows
while (newindex <= end) and (self.type(newindex) == 'separator'):
newindex += self.numrows
if newindex <= end:
self.activate(newindex)
return 'break'

def _on_key_pageup(self, event):
index = self.index('active')
row = index % self.numrows
newindex = index - row
while self.type(newindex) == 'separator':
newindex += 1
self.activate(newindex)

def _on_key_pagedown(self, event):
index = self.index('active')
row = index % self.numrows
newindex = min(self.index('end'), index + (self.numrows - row - 1))
while self.type(newindex) == 'separator':
newindex -= 1
self.activate(newindex)

def _on_key_home(self, event):
newindex = 0
while self.type(newindex) == 'separator':
newindex += 1
self.activate(newindex)

def _on_key_end(self, event):
newindex = self.index('end')
while self.type(newindex) == 'separator':
newindex -= 1
self.activate(newindex)

#--

if __name__ == "__main__":

def show_menu(event):
menu = tkinter.Menu(tearoff=0)
for label in ["one","two","three","four"]:
submenu = GriddedMenu(menu)
menu.add_cascade(label=label, menu=submenu)
for i in range(8):
submenu.add_command(label=f"Item #{i}")
submenu.add_separator()
for i in range(8, 57):
submenu.add_command(label=f"Item #{i}")
submenu.add_separator()
for i in range(57, 72):
submenu.add_command(label=f"Item #{i}")
submenu.add_separator()
for i in range(72, 101):
submenu.add_command(label=f"Item #{i}")
submenu.add_separator()
subsubmenu = tkinter.Menu(submenu)
submenu.add_cascade(label='foo', menu=subsubmenu)
subsubmenu.add_command(label='bar')
submenu.add_separator()
menu.tk_popup(event.x_root, event.y_root)

root = tkinter.Tk()
tkinter.Label(root, text="<1> Left click to show menu").pack()
tkinter.Label(root, text=" to exit").pack()
root.bind("<1>", show_menu)

Re: [Tkinter-discuss] Navigation in menu with multiple columns

2023-09-14 Thread Michael Lange
Hi Vasilis,

On Wed, 13 Sep 2023 15:57:10 +
Vasilis Vlachoudis  wrote:

> In my application I am dynamically creating cascading menus, where some
> of them have multiple entries. To imrpove the visualization I break
> them into multiple columns using the "columnbreak=1" attribute in the
> Menu.add_command()
>
> The Up/Down keys move correctly the active/highlighted entry up/down
>
> However the Left key closes always the cascade submenu, while I would
> prefer to highlight the entry on the left column, and when it is on the
> left-most column to close the cascade submenu Is there a way to bind
> the Left/Right keys to move left/right in the columns?
>
> Vasilis

could you please post a simple example that shows this behaviour?

Have a nice day,

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Peace was the way.
-- Kirk, "The City on the Edge of Forever", stardate unknown
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Canvas() to Image() fonts

2023-07-29 Thread Michael Lange
Hi Bob,

On Fri, 28 Jul 2023 13:00:10 -0600
Bob Greschke  wrote:

> Hi Michael!
>
> I'm working up to Image.save("something.png"). The program will produce
> a picture for each of five different monitors each day, and then
> they'll end up on a web page, so a .png is desired. The program now
> draws the canvas, then uses an ImageGrab.grab() to make a picture of
> the Canvas. The problem, in Debian/X11/etc. is that you have to be
> logged in and looking at what is going on. If you try to run the
> image-making remotely (ssh -Y'ing), or using a cron job, everything
> works, but the pictures come out blank because there's no valid
> $DISPLAY. I'm trying to get it automated with the Image, however
> forcing me to look at the pictures and watch for anomalies in the
> signals each day is not a bad thing. :)

maybe you could use Canvas.postscript() and then convert the output to
png with psconvert, not sure if this helps with the missing $DISPLAY
though. Plus you might need to stick with a font whose spelling Tk and
postscript agree about (I think Arial would be my first guess here).

Have a nice day,

Michael
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Canvas() to Image() fonts

2023-07-28 Thread Michael Lange
Hi,

On Fri, 28 Jul 2023 09:08:11 -0600
Bob Greschke  wrote:

> Hi!
>
> I'm plotting some stuff to a Canvas() (second-by-second signal-to-noise
> values for GPS satellites) and using something like
>
>
>
> in the program to get the font to use for text labels and stuff on the
> canvas.
>
> I can't figure out how to get the same font for the an Image (so I can
> duplicate the Canvas and save it as a png, of course). Without
> specifying anything the text used on the image looks something like
> Courier.
>

do you use Canvas.postscript() to export the canvas contents to an image?
If yes, the problem is probably that Tk and postscript disagree about the
exact spelling of the font name and so postscript falls back to some
default font.

(As a side note:

PROGPropFont = Font(font = Entry()["font"])

seems a bit over-complicated to me, simply doing

PROGPropFont = Font(name = "TkDefaultFont", exists = True)

should give you the same result. scnr :) )

Have a nice day,

Michael

___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Treeview: stop temporarily TreeviewSelect messages

2023-05-31 Thread Michael Lange
Hi Vasilis,

On Wed, 31 May 2023 14:44:35 +
Vasilis Vlachoudis  wrote:

> during the filling of a ttk.Treeview, widget I want to temporarily
> disable the <> (to restore the previously selected
> items), and re-enable it at the end. However, when I unbind the
> <> event the messages are still send. See the following
> demo code. I would expect that during the filling no <>
> message will be send, however I get hundreds of messages at the end
>

the problem appears to be that the binding is restored before the calls in
the "for" loop in your fill() function are processed. If we add a
strategic update() to your function it seems to work as expected:

def fill(event=None):
t.unbind("<>")
for i in range(1000):
item = t.insert("",tk.END,text=f"Item {i}")
if i&1==0: t.selection_add(item)
t.update()
t.bind("<>", tvselect)

update_idletasks() doesn't seem to be sufficient here.

Have a nice day,

Michael

___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Maybe a bug about tk.Text and tk.Label

2023-05-08 Thread Michael Lange
Hi,

On Sun, 7 May 2023 08:34:29 +0800 (CST)
张小平 <13295564...@163.com> wrote:

> When i use Text or Label to show  this :
> [
> [1,"PAGE",{"id":"w"}],
> [2,"Text",{"caption":"This is first GUI Page,totally different form
> HTML."}] ]
>
>
> It shows this:
> {1 PAGE {{'id': 'w'}}} {2 Text {{'caption': 'This is first GUI Page,
> totally different form HTML.'}}}
>

you mean if you pass the list directly to the Label's text option?
In this case, the "magic" of tkinter apparently converts the Python list
into a proper Tcl list which is what you see here.
If you want the Python list to be displayed as label text, you need to
enclose it in quotation marks, as in

s = '''[
[1,"PAGE",{"id":"w"}],
[2,"Text",{"caption":"This is first GUI Page,totally different form
HTML."}] ]'''
Label(parent, text=s, justify='left')

Have a nice day,

Michael
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Program continuing execution while tkinter window is open

2022-09-22 Thread Michael Lange
Hi,

On Thu, 22 Sep 2022 16:17:50 +
Massimo POZZONI via Tkinter-discuss  wrote:

>
> I'm wondering if there is any way to have a tkinter window running,
> while the main program is continuing its execution. I tried with
> threading but with no success.
>
> So far I always got the program to wait until the tkinter window is
> closed.
>
> Is there any way to have the python main program to continue the
> execution while a tkinter window is open?

I am not sure what you actually want to achieve; when using threads you
need to make sure that the Tcl interpreter (inside which the tkinter
window is running) runs in the main program thread and that you must
*never* do any calls to tkinter from within any of the child threads. For
interaction between tkinter and the child threads you can for example use
Lock or Condition objects to safely update some variable value from the
child thread and an after() loop to query the variable value on the Tk
side.

Below a primitive example:

##

from tkinter import *
from threading import Thread, Lock
from time import sleep
from signal import signal

root = Tk()
s = IntVar()
s.set(0)
Label(root, textvariable=s).pack(pady=30, padx=70)

x = 0
run = True
lock = Lock()

def quit(*args):
global run
# make sure the child stops before we quit
run = False
root.quit()
root.protocol('WM_DELETE_WINDOW', quit)
# make sure keyboard interrupt is handled properly
signal(2, quit)

def poll():
lock.acquire()
s.set(x)
print('current value ->', x)
lock.release()
root.after(500, poll)
poll()

def incr():
global x
while run:
lock.acquire()
x += 1
lock.release()
sleep(1)
print('child thread done')

t = Thread(target=incr)
t.start()

root.mainloop()

##

Have a nice day,

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Without facts, the decision cannot be made logically.  You must rely on
your human intuition.
-- Spock, "Assignment: Earth", stardate unknown
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] TKinter ttk combobox Focusout event

2022-09-21 Thread Michael Lange
Hi,

On Tue, 20 Sep 2022 08:05:36 +
Massimo POZZONI via Tkinter-discuss  wrote:

(...)
> My problem is that I need an event that is triggered when the overall
> combox widget is left, which is not the FocusOut, because when I open
> the drop-down menu I am still using the widget, and it is not the
> <> because if I left the widget after writing inside
> the associated Entry, the event is not triggered because no selection
> from list happens.
>
> Is there any way to have an event that is triggered when the overall
> combobox is left, but not when the drop-down list is opened?

maybe a workaround might help.
As far as I know there is no simple way to directly access ttk subwidgets
from tkinter, but with a simple trick you could check if the focus went
from the combobox's entry to the drop down list, as in this example:



from tkinter import *
from tkinter import ttk

root = Tk()
b = Button(root, text='Hi')
b.pack(padx=100, pady=30)

v = StringVar(value='foo')
# define a unique widget name for the combobox
c = ttk.Combobox(root, name='unique_name',
textvariable=v, values=('foo', 'bar', 'bla'))
c.pack(pady=30)

def do_something():
print('Doing something...')

def on_focus_out(event):
# check if the drop-down list has keyboard focus
if 'unique_name.popdown' in str(root.tk.call('focus')):
print('Drop-down list opened.')
else:
do_something()

c.bind('', on_focus_out)
root.mainloop()



Alternatively one could skip that uinque-name thing and use the fact that
focus_get() crashes when the drop down list has focus, with a modified
event callback:

def on_focus_out(event):
try:
c.focus_get()
do_something()
except KeyError:
pass

Not sure about this one, maybe it might fail if the focus goes from the
combobox directly to some other ttk subwidget? In the
simplified example program above both versions seem to work.

Have a nice day,

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Every living thing wants to survive.
-- Spock, "The Ultimate Computer", stardate 4731.3
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] 4k HiDPI displays and tkinter [cont]

2022-03-17 Thread Michael Lange
Hi,

On Thu, 17 Mar 2022 09:47:16 +
Vasilis Vlachoudis  wrote:

> Hi Michael,
>
> no I am using the default fonts.
> What is different is the I have set a high DPI for the X-server to
> match the screen resolution.
>
> I saw in the page
> https://www.tcl.tk/man/tcl/TkCmd/ttk_treeview.html
>
> under "Styling Options'
> there is parameter to set the -rowheight
> that needs to be defined as
>
> ttk::style configure Treeview \
>  -rowheight [expr {[font metrics font -linespace] + 2}]
>
> however I could not find how to call this command, and when
> If I do the following
>
> style = ttk.Style()
> style.configure("Treeview", rowheight="30")
>
> it works, but it is not dynamic with the font size/dpi

you could do something like

>>> f=font.Font(name='TkDefaultFont', exists=1)
>>> rowheight=f.metrics('linespace')+2
>>> rowheight
17

This value is in pixels; I am not sure, if you did something to the
dpi setting, maybe you still need to increase this value somehow according
to the scaling factor in use, which you should be able to query with:

>>> root.tk.call('tk', 'scaling')
1.2450980392156863

I am just doing guesswork here, though.

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

It would be illogical to kill without reason.
-- Spock, "Journey to Babel", stardate 3842.4
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] 4k HiDPI displays and tkinter [cont]

2022-03-17 Thread Michael Lange
Hi,

On Wed, 16 Mar 2022 16:16:36 +
Vasilis Vlachoudis  wrote:

> On the same topic of HiDPI screens, the Treeview seems to calculate
> wrongly the font height (see attach image)
> Do you know any way to correct that?
>

are you possibly using a point-sized font? If yes, maybe there is some
dpi issue again?

Regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

No problem is insoluble.
-- Dr. Janet Wallace, "The Deadly Years", stardate 3479.4
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] 4k HiDPI displays and tkinter

2021-07-14 Thread Michael Lange
Hi,

On Wed, 14 Jul 2021 14:22:37 +
Vasilis Vlachoudis  wrote:

> I am trying to change the tk widgets to ttk, so I can globally correct
> them, e.g. root=tk.Tk()
> sb=ttk.Scrollbar(root)
> sb.pack(side=tk.RIGHT,fill=tk.Y)
> style=ttk.Style()
> style.configure("TScrollbar", width="10m")
>
> However the width doesn't apply on the up/downarrows which they remain
> tiny. Where I can find the style options that I can change?
> I've tried
> style.configure("TScrollbar.uparrow", width="10m")
> but doesn't work

looking at defaults.tcl helps :)

At least here on X11 with default ttk style

st.configure('TScrollbar', width='10m', arrowsize='10m')

works.

With the default style scaling a checkbutton with

st.configure('TCheckbutton', indicatordiameter='10m')

also works, not with the "alt" theme though (I guess they are using a
bitmap there again).

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Without freedom of choice there is no creativity.
-- Kirk, "The return of the Archons", stardate 3157.4
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] 4k HiDPI displays and tkinter

2021-07-13 Thread Michael Lange
Hi,

On Mon, 12 Jul 2021 20:31:57 +0100
E Paine  wrote:

> > - all widths like borderwidths, decorations, separators etc, set in
> > pixels do not scale with the dpi settings. Could we use "mm" for their
> > settings instead?
>
> Definitely! The defaults in Tk use pixels, but you can use mm for
> lengths: tk.Label(root, text="foo", borderwidth="5mm", relief="groove")
>
> > - checkbox, radiobox the indicator appears tiny wrt the text
>
> This may be related to https://bugs.python.org/issue41969, in which case
> you're just waiting for your repos to update Tk.

Not sure, this seems to be a windows-specific thing. The OP was more
interested in ways to let Tk do the job by itself (at least that is what
I assumed :) .

>
> > Is there a way to detect from tkinter a high res display and force a
> > window scaling x2 for everything?
>
> IDLE has a `fix_scaling` method. Maybe you could use something similar?
> https://github.com/python/cpython/blob/da2e673c5/Lib/idlelib/run.py#L313

Looks like this will scale only font sizes. To scale "everything" you can
try to use the "tk scaling" command directly, like

root.tk.call('tk', 'scaling', chosen_dpi / 72.0)

(I thought that's what Vasilis already does).

Please note that this must be called early in the code, before any
widgets are created.

According to `man tk` this should scale everything that is measured in
"physical units" like mm, points or inches, but it won't scale e.g. a
borderwidth or a font size given in pixels. Obviously it won't scale
images either, which I guess is the problem with the check- and
radiobuttons; the indicators are probably just hard-coded images or
bitmaps.

Another problem with that fix_scaling() method might be that it relies on
the scaling factor already in use (I guess), which may be treacherous, at
least if you have a cheap monitor (like I do :) . These monitors often
report incorrect EDID data, which lead to an incorrect default dpi value
(in my case iirc with default settings everything appeared too small on
the screen, like a 100 mm line being displayed at 80 mm size or so; with
linux I had to manually override the dpi X11 uses to work around this;
I never bothered to check with windows, but I suppose that problem
still exists).

When using "tk scaling" you can add some configuration switch to let the
user decide which dpi value to use.

Best regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Without followers, evil cannot spread.
-- Spock, "And The Children Shall Lead", stardate 5029.5
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] 4k HiDPI displays and tkinter

2021-07-12 Thread Michael Lange
Hi,

On Mon, 12 Jul 2021 17:13:18 +
Vasilis Vlachoudis  wrote:

> Recently I've got a 4k laptop, and the first experience with linux and
> the 4k display is quite painful. I am still trying to tune it but for
> the moment my tkinter applications do not render nicely on such a
> display.
> - all widths like borderwidths, decorations, separators etc, set in
> pixels do not scale with the dpi settings. Could we use "mm" for their
> settings instead?

why not try it?

>>> from tkinter import *
>>> r=Tk()
>>> b=Button(r, bd='2m')
>>> b.pack()

looks like a 2 mm border here ;)
But then:

>>> b.configure(width='40m')
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.7/tkinter/__init__.py", line 1485, in configure
return self._configure('configure', cnf, kw)
  File "/usr/lib/python3.7/tkinter/__init__.py", line 1476, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: expected integer but got "40m"
>>> b.configure(bitmap='questhead')
>>> b.configure(width='40m')
>>> # this worked!

So, things might be a bit tricky :)


> - checkbox, radiobox the indicator appears tiny wrt the text

Agreed, these may be even more tricky.

>
> Is there a way to detect from tkinter a high res display and force a
> window scaling x2 for everything? What is your experience with such
> displays?

I don't have any experience with 4k displays, but had a similar problem
when I set up a little app I wanted to run on my 1080p TV. From 3 m
distance even with that display a highlight thickness of 1 pixel is hard
to detect for my old eyes.
I ended up with an option database that changed the defaults of font
size, highlightthickness etc. to values that seemed to me appropriate in
that context.
Detecting the resolution of the display in use should be easy enough,
just use winfo_screenwidth() ; the values for such an option database
could then easily be calculated depending on the screen size, so maybe
fiddling with the dpi is not necessary.

With ttk widgets things might be more difficult, though. Might be that
the best way in the end is to edit one of the existing ttk themes to fit
your needs and save it as themename_4k or so.
And the checkbutton/radiobutton indicators still will remain tiny (as
well as any other images may seem too small).

Best regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

There is a multi-legged creature crawling on your shoulder.
-- Spock, "A Taste of Armageddon", stardate 3193.9
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] [Solved] Re: Trying to center the output of Canvas.postscript() onto A4 page

2021-07-03 Thread Michael Lange
Hi,

On Sat, 3 Jul 2021 12:22:17 +1200
Greg Ewing  wrote:

> On 3/07/21 3:58 am, Michael Lange wrote:
> > Or maybe the printer has some
> > sort of hard-wired margin on each side that it cannot print on and
> > that ought to be taken into account
>
> Yes, most printers have an unprintable area of a few mm, and
> it's not necessarily symmetrical. The manual would presumably
> tell you about it, if it hasn't succumbed to Manual Existence
> Failure over the years. :-)

the manual on the CD that came with the printer actually does.
According to the manual the margin is 3.4 mm left and right and 3.0 mm at
the top and 12.7 mm at the bottom for A4 paper.
If my calculation is correct this would put the horizontal center of the
printable area at 292.8 points. Since try-and-error experiments show that
290.2 is better, I assume that the precision of the manual is
probably limited.

Best regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Blast medicine anyway!  We've learned to tie into every organ in the
human body but one.  The brain!  The brain is what life is all about.
-- McCoy, "The Menagerie", stardate 3012.4
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Trying to center the output of Canvas.postscript() onto A4 page

2021-07-02 Thread Michael Lange
On Fri, 2 Jul 2021 10:14:10 +0200
Paul Malherbe  wrote:

> Hi Michael, this might help
> 
> http://www.atmos.albany.edu/facstaff/rmctc/psrotate/
> signature Regards
> 
> Paul Malherbe

thanks for the tip, it might possibly.
Meanwhile I found a better solution, though (see my other
post... understanding Tk command options helps :)

Have a nice day :)

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Do you know the one -- "All I ask is a tall ship, and a star to steer
her by ..."  You could feel the wind at your back, about you ...  the
sounds of the sea beneath you.  And even if you take away the wind and
the water, it's still the same.  The ship is yours ... you can feel her
... and the stars are still there.
-- Kirk, "The Ultimate Computer", stardate 4729.4
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


[Tkinter-discuss] [Solved] Re: Trying to center the output of Canvas.postscript() onto A4 page

2021-07-02 Thread Michael Lange
Hi,

thanks for the feedback!

On Fri, 2 Jul 2021 09:17:41 -0300
Emiliano Gavilan  wrote:

> You can achieve what you want with the correct set of options to the
> canvas postscript() method, documented here:
>
> https://www.tcl.tk/man/tcl8.6/TkCmd/canvas.html#M61

yes, I have been looking at that man page the other day for what felt
like an hour, but failed to get the point :-)
Well, maybe at least I can partially blame that failure on the man page
authors, since there is nothing mentioned that the default values are
apparently pagex=306.0, pagey=396.0 which appears to be half the size of a
page in U.S. letter format measured in printer points. This sort of
information might have helped :-)

>
> In your case:
>
> canvas.postscript(pagex=0, pagey=0, pagewidth=594, pageheight=841,
> pageanchor="sw", file="test.eps")
>
> This will scale the output to fit into an A4 page. The final result
> will depend also of the area of the canvas
> being exported, controlled by the x, y, width and height options (the
> default is to export the visible part).
> A bit of experimentation will get you the correct values of these
> options.

No, maybe I did not describe what I want to achieve accurately; I do not
want the output to be scaled, but to be printed in the exact requested
millimeter-size.
I got it now though that this can be achieved by setting the pagex
and pagey values accordingly; I gather that for an A4 page this should be
approx. pagex=298, pagey=421 with pageanchor='center'. For some reason
here this is still a little bit off, but maybe this can be blamed on the
worn mechanics of my cheap old printer. Or maybe the printer has some
sort of hard-wired margin on each side that it cannot print on and that
ought to be taken into account (if the users only knew about it).

Anyway, I wasted some paper and found that for this particular printer
values of pagex=290.2 and pagey=419.5 seem to be as close to perfect as
it gets with that sort of hardware.

Thanks again, and have a nice day :)

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

History tends to exaggerate.
-- Col. Green, "The Savage Curtain", stardate 5906.4
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


[Tkinter-discuss] Trying to center the output of Canvas.postscript() onto A4 page

2021-07-02 Thread Michael Lange
Hi,

I want to print the contents of a Canvas widget by feeding the output of
the postscript() command to lpr (I am working with linux here).

I would like that Canvas "screenshot" to be centered on the printed page
(in my case these are A4 pages which are standard here).
Unfortunately I do not seem to be able to do this. After a number of
unsuccessful tries to fiddle with lpr I finally found that the problem
appears to be that the generated postscript file always seems to be
designed for pages in U.S. letter format, obviously this part in the
postscript:

%%Page: 1 1
save
306.0 396.0 translate

is responsible for that; I tried and manually changed the coords that (as
it seems) are passed to the "translate" command and the position of the
Canvas rectangle (which might be for example 12x12 cm or so) on the page
changes.

So, is there any way to tell the postscript() command to use a page size
other than U.S. letter for its output that I missed, or alternatively,
does anyone know about a 3rd party tool available for linux that could be
used to "convert" the postscript() output from letter to A4 format?

Thanks in advance

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

"Get back to your stations!"
"We're beaming down to the planet, sir."
-- Kirk and Mr. Leslie, "This Side of Paradise",
   stardate 3417.3
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Exception protection to tk calls

2021-04-01 Thread Michael Lange
Hi,

On Thu, 1 Apr 2021 07:54:40 +
Vasilis Vlachoudis  wrote:

> Thank you Michael,
>
> >> grab_release() on a widget that has already been destroyed or, in
> >> the/
>
> this is also my understanding, however the places that happens are on
> Dialog code(s) like
>
(...)
>
> My impression is that on slow network connections (using remote X11
> session), sometimes the dialog is displayed before the wait_visibility
> is being executed and if the user closes the window from the window
> manager, it arrives to the focus_set, grab_set or wait_window with a
> window that doesn't exist and then I get the error message.

if this is the case, maybe calling self.withdraw() early in the __init__
method and then calling protocol() before deiconify() might help?
Just a guess, though. At least it sounds a bit like the users manage to
press the "X" button from the window decorations before the protocol()
has been applied.

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Totally illogical, there was no chance.
-- Spock, "The Galileo Seven", stardate 2822.3
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Exception protection to tk calls

2021-03-31 Thread Michael Lange
Hi,

On Wed, 31 Mar 2021 06:53:26 +
Vasilis Vlachoudis  wrote:

> Is there any recommendation which tkinter calls have to be protected
> with an exception handling I occasionally receive traceback errors from
> my users on various calls like: grab_current, grab_release, focus_get
> most of the times I protect them with with a TclError handler catching
> exceptions like_tkinter.TclError: bad window path name
>
> Also which type of exception has to be protected, this is the first
> time I've got a KeyError from a tkinter call, which normally should be
> innocent focus_get()"

it is a bit hard to guess what's going on without a real code example.
It seems like you get these errors when either calling for example
grab_release() on a widget that has already been destroyed or, in the
last example, calling focus_get() while a messagebox is being displayed
(not sure how this can actually happen in real-world code, I was only
able to reproduce that error message with a non-sensical example, like

>>> def foo():
... root.after(1000, lambda: print(root.focus_get()))
... messagebox.showinfo()
...
) .

I know that this is not really an answer to your question, but my guess
is that all of these situations may actually be caused by programming
errors which, once they have been discovered, should rather be fixed
properly than worked around with a try-except clause.

For example, if the window on which grab_release() is called might no
longer exist, something like

if widget.winfo_exists():
widget.grab_release()

might do the trick.

If you want to use try-except protection anyway, I don't think that there
is any general rule which methods should be protected with which
exception type. I think the only way to find out is to examine the
tkinter code and find out for yourself which exception(s) are likely to
occur. For example with focus_get() I think the KeyError caused by
nametowidget() is probably the only exception one might expect.
Of course one could always play it safe with something like:

try:
focus = self.focus_get()
except:
focus = None

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Death, when unnecessary, is a tragic thing.
-- Flint, "Requiem for Methuselah", stardate 5843.7
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] How to install jpeg support in Tkinter

2020-11-07 Thread Michael Lange
Hi,

On Thu, 5 Nov 2020 21:52:08 -0800
Donald Rozenberg  wrote:

> Hi,
>
> I am looking for a way to install Img in Windows 10 in such a way that
> the image support particularly for jpegs is available to the Tcl/Tk
> included in Tkinter.
>
> I have written a programming tool called PAGE in Tcl/Tk that is called
> by Tk.eval. That tool would be more effective if it could support
> jpegs. In Linux I can install the package libtk-img and then Tkinter
> seems able to support jpegs.  I don't know how to make a similar
> installation in Windows.

I haven't tried myself, but I believe downloading the appropriate version
(32/64 bit) from

https://sourceforge.net/projects/tkimg/files/tkimg/1.4/tkimg%201.4.11/

, unpacking the .zip archive and then copying the Img1.4.11 folder into
your Python install's Tcl directory should do the trick.

If you want to put tkimg somewhere else, for example into your own
program's path, doing something like

self.tk.call('lappend', 'auto_path', '')

before calling "package require Img" should work, too.

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Even historians fail to learn from history -- they repeat the same
mistakes.
-- John Gill, "Patterns of Force", stardate 2534.7
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] horizontal line in Text

2020-01-26 Thread Michael Lange
Hi,

On Fri, 24 Jan 2020 16:44:30 +
Vasilis Vlachoudis  wrote:

> Thanks
> That's the easiest from all, and for my purpose it works just fine
>
> Vasilis
>
>
>
> 
> From: Bryan Oakley [bryan.oak...@gmail.com]
> Sent: Friday, January 24, 2020 16:04
> To: Vasilis Vlachoudis
> Subject: Re: [Tkinter-discuss] horizontal line in Text
>
> What I've done in the past is insert a single newline, and then apply a
> tag that uses a one or two pixel tall font, and then a background color
> or a border. When you add a tag on a newline, the background and border
> is always drawn to the right margin and is adjusted as the window is
> resized, yielding what looks like a line.
>
> def insert_hr(text, index):
> text.tag_configure("hr", font=("Times", -2), background="red")
> text.insert(index, "\n", "hr")
> insert_hr(text, "2.0")

thanks for sharing! You are right, this is much better than tinkering
with embedded Frames. It never occured to me that this could be done so
easily.

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

A princess should not be afraid -- not with a brave knight to protect her.
-- McCoy, "Shore Leave", stardate 3025.3
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] horizontal line in Text

2020-01-24 Thread Michael Lange
Hi,

On Fri, 24 Jan 2020 00:18:20 +
Alan Gauld via Tkinter-discuss  wrote:

> On 16/01/2020 13:14, Vasilis Vlachoudis wrote:
> > Hi all,
> >
> > is it possible to draw a horizontal line in the Text() widget,
> > something like the  in html, extending all over the widget.
>
> Would a line of spaces with the underline turned on in the font work?
> If you use a monospace font the length should be fairly predictable.
>
> Just a thought.

I think the problem with all text based solutions is that these "lines"
will not resize along with the text widget and worse, might line-break
when the widget size is being reduced.

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

The people of Gideon have always believed that life is sacred.  That
the love of life is the greatest gift ... We are incapable of
destroying or interfering with the creation of that which we love so
deeply -- life in every form from fetus to developed being.
-- Hodin of Gideon, "The Mark of Gideon", stardate 5423.4
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] horizontal line in Text

2020-01-16 Thread Michael Lange
Hi,

On Thu, 16 Jan 2020 13:14:08 +
Vasilis Vlachoudis  wrote:

> Hi all,
>
> is it possible to draw a horizontal line in the Text() widget, something
> like the  in html, extending all over the widget.

I have done this before with an embedded Frame widget, however changes to
the Text widget size have to be taken into account and the Frame widgets
need to be resized accordingly, which makes things a bit complicated.
Maybe there is a simpler way to do that, but I don't know any.

I'll post the important parts of the code I used below.

I hope this helps :)

Michael



def send_hor_rule(self, *args):
xoff = int(self.text['highlightthickness']) + \
   int(self.text['bd']) + int(self.text['padx']) + 15 # 15 px. 
extra padding
w = self.text.winfo_width() - 2 * xoff
f = tkinter.Frame(self.text, height=4, highlightthickness=0,
  width=w, relief='ridge', bd=2, bg='gray60')
i = self.text.index('insert')
self.text.window_create('insert', window=f, align='center')
self.text.horRules.append((i, f))


def _configureHorRules(self, *event): # callback for Configure events
if self.text.horRules:
# _getMaxLineSize() is slow, but calling it on every Configure
# event seems to be the only way to make this work reliably
maxlinesize = self._getMaxLineSize()
w = self.text.winfo_width()
xoff = int(self.text['highlightthickness']) + \
   int(self.text['bd']) + int(self.text['padx'])
w_vis = w - 2 * xoff
m = max((w_vis, maxlinesize))
for (i, w) in self.text.horRules:
w.configure(width=m)
return

def _getMaxLineSize(self, *event):
# calculate the max. required size of a line to use as size
# for the horizontal rules
numlines = self.text.count('1.0', 'end', 'lines') or 0
xpixmax = 0
if numlines:
numlines = numlines[0]
horRuleLines = [
int(i.split('.')[0]) for (i, w) in self.text.horRules]
for i in range(1, numlines + 1):
if i in horRuleLines:
# if a line with a horRule is the biggest, the hor. rule
# might get bigger with each reconfiguring, so we must
# not take these lines into account
continue
xpix = self.text.count(
'%d.0' % i, '%d.0 lineend' % i, 'xpixels')
if xpix and xpix[0] > xpixmax:
xpixmax = xpix[0]
return xpixmax

###


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

The sooner our happiness together begins, the longer it will last.
-- Miramanee, "The Paradise Syndrome", stardate 4842.6
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] wait_window exception

2020-01-06 Thread Michael Lange
Hi,

On Mon, 6 Jan 2020 09:40:42 +
Vasilis Vlachoudis  wrote:

> Happy new decade everyone!
>
> Interesting enough, removing the "deiconify()" the problem didn't
> reoccur. Maybe, not enough people test it, but I am happy that works on
> windows, linux and mac for the moment without the problem.

I am glad you finally got it working. Now when I look at your original
post it seems there hasn't been a call to withdraw() first, maybe this
was the problem? Otherwise it still would seem odd to me.

Best regards, and a happy new year (or decade :) to all of you!

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Actual war is a very messy business.  Very, very messy business.
-- Kirk, "A Taste of Armageddon", stardate 3193.0
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] wait_window exception

2019-12-26 Thread Michael Lange
Hi,

On Wed, 25 Dec 2019 17:04:04 +
Vasilis Vlachoudis  wrote:

> Thanks Michael
> my best wishes to you too.
> The close method is the following, apart some bookkeeping nothing
> special.
>   # --
>   def close(self):
>   FileDialog._active = False
>   FileDialog.width   = self.winfo_width()
>   FileDialog.height  = self.winfo_height()
>   FileDialog.sash= [self.fileList.paneframe.sash_coord
> (i)[0] for i in range(len(self.fileList.listboxes())-1)]
>   tkExtra.ExListbox.resetSearch()
>   self.grab_release()
>   self.destroy()
>
> I've realized that the "deiconify()" was creating some problems on
> Windows, so I removed it, and it seems it works better. When I will
> deploy this version I will know after if it still generates problems.

it seems rather odd if actually deiconify() is the culprit here.
Another thought that occurred to me, is the window path name ".!flair.!
configdialog3.!opendialog\" assigned manually? If yes, is it possible
that a second window that tries to go by the same path name interferes
here?

Regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

If some day we are defeated, well, war has its fortunes, good and bad.
-- Commander Kor, "Errand of Mercy", stardate 3201.7
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] wait_window exception

2019-12-24 Thread Michael Lange
Hi,

sorry for the late reply.

On Wed, 18 Dec 2019 15:54:04 +
Vasilis Vlachoudis  wrote:

> What is the correct way to open a dialog and wait for the window
> Typically I am doing the following
> on a class subclassed of Toplevel
>
>   # --
>   def __init__(self, title=None,
>   master=None,
>   **kw):
>
>
>   super().__init__(master, class_="FileDialog")
>   self.transient(master)
>   self.title(title)
>   self.protocol("WM_DELETE_WINDOW", self.close)
>
> # ... all initialization etc...
>
>
>   def show(self):
>   self.focus_set()
>   try:
>   self.deiconify()
>   self.wait_visibility()
>   self.update_idletasks()
>   self.grab_set()
>   except tk.TclError:
>   pass
>   self.wait_window()
>
> Unfortunately, several times when the system is not very responsive I
> get a traceback report from my users like
>   ...
>   File \"/usr/local/flair/lib/bFileDialog.py\", line 361, in show
> self.wait_window()
>   File \"/usr/lib64/python3.7/tkinter/__init__.py\", line 642, in
> wait_window self.tk.call(\'tkwait\', \'window\', window._w)
> _tkinter.TclError: bad window path name \".!flair.!configdialog3.!
> opendialog\"
>
>
> Is there the possibility that the user clicks on the "Ok" or "Cancel"
> button before the code execution arrives to the wait_window(), so when
> it is there it gives the error message. Or can be something else that I
> am missing.

I am not sure what may be the problem here. What does the close() method
do exactly, is it possible that the problem lies there?

A happy Christmas to all of you!

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

One of the advantages of being a captain is being able to ask for
advice without necessarily having to take it.
-- Kirk, "Dagger of the Mind", stardate 2715.2
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] The Async delete problem....

2019-12-15 Thread Michael Lange
Hi,

On Sun, 15 Dec 2019 18:29:18 +
Mike Barnett  wrote:

> I've been fighting this error for a couple of years now and just when I
> think I've got it understood and "Fixed", it bites me again.
>
>
>
> Here's the error:
>
>
>
> Exception ignored in: 
>
> Traceback (most recent call last):
>
>   File "X:\Python\python3.8\lib\tkinter\__init__.py", line 351, in
> __del__
>
> if self._tk.getboolean(self._tk.call("info", "exists", self._name)):
>
> RuntimeError: main thread is not in main loop
(...)

> It happens in programs that are multi-threaded.  The threads do NOT
> make any tkinter calls and do not touch any variable that has anything
> to do with tkinter.
>
> What appears to be happening is that tkinter objects are marked to be
> deleted and then when Python's garbage collect runs and actually does
> the deletes, it is happening in the context of the thread, not the main
> thread.
>
> My way around this at the moment is to keep the widgets around for the
> duration of the program rather than deleting them in any way.  I would
> really like to get this solved though as other people using my code run
> into this and don't know what to do.
>
> Any ideas on how to dispose of widgets / windows in a way that
> immediately calls these delete methods? Or is it possible to tell
> tkinter that despite the deletes being called from another thread it's
> OK because the thread isn't actually changing anything at the same time
> as the main thread?
>

I am not sure what is happening here. It sounds a bit as if the tk gui is
not in the main program thread? If yes, maybe this causes the problem; as
far as I know it is imperative that the tk mainloop is inside
the main program thread.

Regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

We're all sorry for the other guy when he loses his job to a machine.
But when it comes to your job -- that's different.  And it always will
be different.
-- McCoy, "The Ultimate Computer", stardate 4729.4
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] How to handle any Windows message (eg. WM_GETOBJECT)?

2019-12-10 Thread Michael Lange
Hi,

On Tue, 10 Dec 2019 12:49:27 +0200
Aivar Annamaa  wrote:

> Hi!
>
> It looks like accessibility support in Tk won't happen
> (https://core.tcl-lang.org/tk/tktview/deb6cddecf55c6921281f8f855b6b366aed6467e).
> I'm wondering is it somehow possible to bolt on some accessibility
> support at least on Windows.
>
> It looks like the starting point is that the app should be able to
> provide customized responses to WM_GETOBJECT messages. I didn't find
> such name in Tk source code. Does it mean Tk event loop simply drops
> these? Is it somehow possible to install an extra WM event handler to
> catch these?

have you tried to do something like

def test():
print('hello')
root.wm_protocol('WM_GETOBJECT', test)

I have no idea what WM_GETOBJECT does and if there is any chance that
this will work, though :)

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

I realize that command does have its fascination, even under
circumstances such as these, but I neither enjoy the idea of command
nor am I frightened of it.  It simply exists, and I will do whatever
logically needs to be done.
-- Spock, "The Galileo Seven", stardate 2812.7
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] tkinter.PhotoImage to PIL.Image

2019-12-06 Thread Michael Lange
Hi,

On Fri, 6 Dec 2019 08:36:18 +
Vasilis Vlachoudis  wrote:

> Thanks Michael,
>
> at present my program is based that all the images are loaded as
> tkinter.PhotoImage. I am trying always to keep the python dependencies
> as low as possible. PIL is not required apart when the user wants some
> specific functionality (add-ons)
>
> So for the case that someone wanted to resize them (PIL would be
> required) and I was thinking  to resize them by temporarily converting
> them to PIL.Image and then back to tkinter.PhotoImage.
> Maybe my way is not the cleanest, but rather to do as you propose, load
> them as PIL.Images process and convert them to tkinter.PhotoImage.

maybe you could create a custom Image class that checks at program start
for the presence of PIL and if PIL is present uses scalable PIL
PhotoImages and if not plain tkinter ones, or let it depend on the user
configuration which ones to use.

Regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

All your people must learn before you can reach for the stars.
-- Kirk, "The Gamesters of Triskelion", stardate 3259.2
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] tkinter.PhotoImage to PIL.Image

2019-12-04 Thread Michael Lange
On Wed, 4 Dec 2019 19:25:45 +0100
Michael Lange  wrote:

> resized = im.resize((height, width), IMAGE.ANTIALIAS)
   ^

oops, should be

resized = im.resize((width, height), IMAGE.ANTIALIAS)



.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

The sight of death frightens them [Earthers].
-- Kras the Klingon, "Friday's Child", stardate 3497.2
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] tkinter.PhotoImage to PIL.Image

2019-12-04 Thread Michael Lange
Hi,

sorry for the late replay.

On Sat, 30 Nov 2019 13:52:11 +
Vasilis Vlachoudis  wrote:

> Hi all,
>
> I have several images loaded as tkinter.PhotoImage, I want some to
> resize them The PhotoImage zoom accepts only integer values and the
> result is not that great. While if load them with PIL resize them and
> then convert to PIL.ImageTk it is much better. I found several
> references on how to convert from PIL to tkinter but I cannot find how
> to do the opposite so I can use the PIL resizing with the existing
> tkinter images.

Do you mean something like:

from PIL import Image, ImageTk
im = Image.open("image.png")
resized = im.resize((height, width), IMAGE.ANTIALIAS)
photo = ImageTk.PhotoImage(image=resized)

does not do the trick, you want to pass the tkinter.PhotoImage object to
PIL.Image.open() ? I don't think this is possible, at least without some
sort of trickery. What is it exactly that you want to achieve?

Regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

"What happened to the crewman?"
"The M-5 computer needed a new power source, the crewman merely
got in the way."
-- Kirk and Dr. Richard Daystrom, "The Ultimate Computer",
   stardate 4731.3.
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] ttk styles - is it possible to have one per widget?

2019-11-23 Thread Michael Lange
Hi,

On Fri, 22 Nov 2019 16:00:07 +
Mike Barnett  wrote:

> Hmmm... I didn't see am email go out for this.  Did anyone get this
> email?
>

sure :)

> What I am trying to do is "style" ttk widgets in a way that each one
> can have their own unique settings.  I've not found code or pseudo-code
> that does what I'm looking for.
>
> Is it possible for ttk widgets to work like tk widgets in that each can
> have their own unique settings like background color, text color, etc?


You can do this by defining custom styles that inherit their
properties from the widget's default style and set some or other
properties to custom values, as for example:

from tkinter import *
from tkinter import ttk

root=Tk()
style = ttk.Style()
style.configure('my.TButton', background='red')
style.configure('myOther.TButton', background='blue')
ttk.Button(root, style='my.TButton', text='foo').pack()
ttk.Button(root, style='myOther.TButton', text='bar').pack()

root.mainloop()


I hope this helps

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

The games have always strengthened us.  Death becomes a familiar
pattern.  We don't fear it as you do.
-- Proconsul Marcus Claudius, "Bread and Circuses",
   stardate 4041.2
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Help needed

2019-07-30 Thread Michael Lange
Hi,

On Tue, 30 Jul 2019 15:43:53 +0530
Balasubramani K  wrote:

> I have a questions :
> Cant we use tqdm progress bar in tkinter window ??
> In other words, can't we get a terminal window in tkinter window; where
> whatever the output of the code that is executed should be shown in the
> terminal. like how we use in pycharm or cmd prompt in windows ...etc

actually this can be done, at least with X11; here with debian I can do
something like:

from tkinter import *
from subprocess import Popen

root=Tk()
f=Frame(root, container=1, width=300, height=300)
f.pack(fill='both', expand=1)
pipe = Popen(('urxvt', '-embed', str(f.winfo_id(
root.mainloop()

Still, I am not so sure if this is a good idea.
First, those embedded windows can be tricky by themselves; there may also
be DE/WM dependent issues (no idea if this works on windows or OSX at
all).
Then you will have to consider user interactions with the terminal,
for example what if the user decides to simply type "exit" at the command
prompt? Or hits Ctrl+\ while the process is running?

Of course I do not know what you want to achieve in detail, but maybe if
you want to use a gui with tqdm it would be a better approach to catch
the string (I guess the "data" in your code snippet?) and instead of
printing it to stdout just putting it on a tkinter Label.
I don't know about tqdm, maybe you could change the output format a bit
to omit the progress bar at all, calculate the value for the
ttk.Progressbar with the percent value and put an output string like

47% 76442/161258.81970214844 [14:12<16:26, 86.00KB/s]

on a Label next to the progress bar. That would give the user all the
information they need, would be easier for you to handle, be more
reliable and surely make a better looking gui.

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

"Life and death are seldom logical."
"But attaining a desired goal always is."
-- McCoy and Spock, "The Galileo Seven", stardate 2821.7
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Help needed

2019-07-30 Thread Michael Lange
Hi,

On Mon, 29 Jul 2019 15:26:30 +0530
Balasubramani K  wrote:

> Hi ,
> I'm using following modules in python 3:
> import requests
> import os
> from tqdm import tqdm
>
>
> a piece of code from my script,
>
> requests.get(url, stream=True,allow_redirects=True)
> total_size = int(r.headers['content-length'])
> with open(SaveLocation + SaveFilename, 'wb') as f:
> for data in tqdm(iterable=r.iter_content(chunk_size=Chunk_size),
> total=total_size / Chunk_size, unit='KB', desc=SaveFilename):
> f.write(data)
> f.close()
>
> when I run the python file in terminal I get output as below :
>
> 47%|▋ | 76442/161258.81970214844 [14:12<16:26, 86.00KB/s]
>
> this progress bar I got it from a module called tqdm
>
> Now I'm planning to make UI,  using tkinter with start stop button.
> but when I click start button I need the same tqdm progress bar output
> in the tkinter window

I have used the ttk.Progressbar with external shell commands; if you
don't necessarily need to use tqdm maybe you could use the same technique
for what you are doing.
I added a quick-and-dirty example how to do this below; in the example I
used the command "cdrdao disk-info" on linux, which when no disc is in
the drive will try for about 10 sec. to make sense of the non-existing
disc before giving up, printing "Unit not ready" to stderr for 10 times in
the process which I use here to draw the progress bar.
The gui remains responsive without having to use threads (as you can see
when you hit the stop button).
If you don't need any external command but just want to compare file
sizes, the code may become even simpler.

I hope this helps

Michael



from tkinter import *
from tkinter import ttk
from subprocess import Popen, PIPE
import os, fcntl

root = Tk()
root.pipe = None
f = Frame(root)
f.pack(fill='both', expand=1)
p = ttk.Progressbar(f)
p.pack(padx=100, pady=(100,10))


MSG = ''
def update_progress(msg):
global MSG
print(msg)
MSG += msg
perc = MSG.count('Unit not ready') * 10
p.configure(value=perc)

def update():
sts = root.pipe.poll()
try:
out = root.pipe.stderr.read()
except IOError:
out = b''
if out:
update_progress(out.decode())
if sts is None:
root.after(200, update)
else:
del root.pipe
root.pipe = None
p.configure(value=100)
print('Process finished with status %d' % sts)

def kill():
if root.pipe:
try:
os.kill(root.pipe.pid, 15)
except:
pass

def start():
global MSG
MSG = ''
p.configure(value=0)
root.pipe = Popen(('cdrdao', 'disk-info'), stdout=PIPE, stderr=PIPE)
fcntl.fcntl(root.pipe.stdout.fileno(), fcntl.F_SETFL, os.O_NONBLOCK)
fcntl.fcntl(root.pipe.stderr.fileno(), fcntl.F_SETFL, os.O_NONBLOCK)
root.after(200, update)

Button(text='stop', command=kill).pack(side='bottom', pady=20)
Button(text='start', command=start).pack(side='bottom', pady=20)

root.mainloop()






.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

I am pleased to see that we have differences.  May we together become
greater than the sum of both of us.
-- Surak of Vulcan, "The Savage Curtain", stardate 5906.4
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Text to postscript

2019-06-18 Thread Michael Lange
Hi,

On Tue, 18 Jun 2019 10:09:08 +
Vasilis Vlachoudis  wrote:

> Thanks Michael,
>
> not exactly what I was looking for.

oh yes, I thought so :)

> I am investigating how difficult is to write my own ps exporter,
> based on the Canvas postscript source code.

This would surely be awesome! In case you succeed please make sure to let
us know :)

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

"What terrible way to die."
"There are no good ways."
-- Sulu and Kirk, "That Which Survives", stardate unknown
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Text to postscript

2019-06-18 Thread Michael Lange
Hi,

On Mon, 17 Jun 2019 12:16:49 +
Vasilis Vlachoudis  wrote:

> Hi all,
>
> Canvas has this nice method to convert it to postscript, which is
> perfect for printing. Is there something similar for Text(), I could
> not find anything internal but if there is something external to
> convert to html, ps, pdf it would be nice.

maybe you could use tkimg to create a "screenshot" of the widget in
postscript format.
To enable tkimg's "window" handler once it's installed you just need to do
something like

root.tk.call('package', 'require', 'img::window')

early in your code.

IIRC by default tkimg's "window" handler will include only the visible
part of the widget, but here:

https://wiki.tcl-lang.org/page/Img

George Petasis posted a recipe that seems to be able to capture the whole
contents of a canvas widget. I don't know how well this actually works
though and if it can be done with a Text widget in the same fashion.


Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

History tends to exaggerate.
-- Col. Green, "The Savage Curtain", stardate 5906.4
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] ttk.Notebook: autohide

2019-06-04 Thread Michael Lange
Hi,

On Sun, 2 Jun 2019 14:22:56 +
Vasilis Vlachoudis  wrote:

> Many thanks
>
> The first solution works ok for me without any flickering

probably it depends on the speed of the machine. With an old and slow
laptop of mine the flickering effect appears to be a bit worse than on my
desktop machine. Changing only the padx by one pixel seems to cause only
a slightly "trembling" effect that is hardly noticable at all, so I guess
the second workaround might be a bit better. (Maybe calling those
workarounds "stupid" the other day was a bit harsh, if there's actually
nothing better the second version might be not so bad)

>
> I think you are right it is a bug in tk, probably they forget
> to invalidate the window

Still I am not sure if I didn't miss something here. I think one bad
thing about ttk is that the more advanced operations on styles and themes
aren't really documented very well, so I always find it hard to find out
how to do things properly, I always end up with some try-and-error
solution.

Best regards

Michael



.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Death.  Destruction.  Disease.  Horror.  That's what war is all about.
That's what makes it a thing to be avoided.
-- Kirk, "A Taste of Armageddon", stardate 3193.0
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] ttk.Notebook: autohide

2019-05-30 Thread Michael Lange
Hi,

On Thu, 30 May 2019 19:49:33 +
Vasilis Vlachoudis  wrote:

> Many thanks Michael.
> The recipe works the tab bar disappears (and reappears), but the space
> of the tabs is not reclaimed. the child-window is not resized to get
> the extra space. If I resize the toplevel window with the mouse then it
> works.

oh, I see. This "works" also vice versa here, the tab only reappears
after resizing the window with the mouse. Too bad, looks like a bug to me.

>
> Is there a way to force the layout manager to recalculate all widgets?
>

I am not sure how to do this, except with an ugly hack like:

def hidetabs(ev):
s.layout('TNotebook.Tab', [])
nb.pack(expand=0)
nb.update_idletasks()
nb.pack(fill='both', expand=1)

But that looks rather stupid and besides causes an annoying "flickering"
effect. The flickering seems to be a bit better with a "minimally
invasive" re-packing, as in

def hidetabs(ev):
s.layout('TNotebook.Tab', [])
info = nb.pack_info()
px = info['padx']
del info['padx']
nb.pack(padx=px + 1, **info)
nb.update_idletasks()
nb.pack(padx=px, **info)

but this looks somehow even more stupid.
But maybe I just miss something obvious?

Best regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

"Can you imagine how life could be improved if we could do away with
jealousy, greed, hate ..."

"It can also be improved by eliminating love, tenderness, sentiment --
the other side of the coin"
-- Dr. Roger Corby and Kirk, "What are Little Girls Made
   Of?", stardate 2712.4
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] ttk.Notebook: autohide

2019-05-29 Thread Michael Lange
Hi,

On Wed, 29 May 2019 13:01:16 +
Vasilis Vlachoudis  wrote:

> Hi all
>
> I am using the ttk.Notebook for an editor like application and I want
> to implement something like autohide functionality for the tabheadings
> when there is only one tab, and to reappear when there are more than
> one.
>
> Is there some function to set the height to 0 for the headings of
> "pack_forget" equivalent in the style?

it seems you can show or hide the tabs with something like:

s=ttk.Style()
# store default layout options
tablayout = s.layout('TNotebook.Tab')
# hide tabs
s.layout('TNotebook.Tab', [])
# show tabs again
s.layout('TNotebook.Tab',tablayout)

Idea borrowed from:
https://stackoverflow.com/questions/26923010/how-do-i-hide-the-entire-tab-bar-in-a-tkinter-ttk-notebook-widget

Best regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

There is an old custom among my people.  When a woman saves a man's
life, he is grateful.
-- Nona, the Kanuto witch woman, "A Private Little War",
   stardate 4211.8.
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Button event calls Leave/Enter

2019-05-16 Thread Michael Lange
Hi,

On Wed, 15 May 2019 05:50:24 +
Vasilis Vlachoudis  wrote:

> Thanks.
> I did what you proposed
> if event.state>=256:  # then mouse event, ignore...
>
> Maybe a bug report should be opened in XFCE? In the X11 events it states
> that Enter/LeaveNotify is only due to the cursor movement
> entering/exiting a window, not a mouse press.
>

fyi, I now filed a bug report here:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=929090

Regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

You speak of courage.  Obviously you do not know the difference between
courage and foolhardiness.  Always it is the brave ones who die, the
soldiers.
-- Kor, the Klingon Commander, "Errand of Mercy",
   stardate 3201.7
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Button event calls Leave/Enter

2019-05-15 Thread Michael Lange
Hi,

On Wed, 15 May 2019 05:50:24 +
Vasilis Vlachoudis  wrote:

> Thanks.
> I did what you proposed
> if event.state>=256:  # then mouse event, ignore...
>
> Maybe a bug report should be opened in XFCE? In the X11 events it states
> that Enter/LeaveNotify is only due to the cursor movement
> entering/exiting a window, not a mouse press.
>

I noticed when trying on Debian Sid that LXDE appears also to be
affected (same behavior as with Xfce). I tried then to ask on debian-user
first if someone knows which package the bug should be reported to
(https://lists.debian.org/debian-user/2019/05/msg00668.html), I
guess probably some library both use.

Regards

Michael




.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

"I think they're going to take all this money that we spend now
 on war and death --"
"And make them spend it on life."
-- Edith Keeler and Kirk, "The City on the Edge of
   Forever", stardate unknown.
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Button event calls Leave/Enter

2019-05-14 Thread Michael Lange
Hi,

On Tue, 14 May 2019 13:53:54 +
Vasilis Vlachoudis  wrote:

> Thanks all for your replies.
> I've saw that there is a difference in the event.state, but I cannot
> find any information on what each bit represents.
>

I modified your leave() callback using the values given at:
https://infohost.nmt.edu/tcc/help/pubs/tkinter/web/event-handlers.html
into:

def leave(event):
s = event.state
b1 = (s & 0x0100) != 0
if b1:
print('leave event with Button 1 pressed', 'event.state:', s)
else:
print('regular leave event', 'event.state:', s)

which actually seems to do the trick (btw., same behavior here with xfce,
so the exact Tk version apparently doesn't matter).
However, there still seems to be no way to tell if it is an actual Leave
event (i.e. mouse pointer dragged out of the window) while Button1 is
pressed or one of those fake-Xfce-Leave events.
The same "fake" events occur here also with Button2 and Button3, so there
might be more event.state values to consider.

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

On my planet, to rest is to rest -- to cease using energy.  To me, it
is quite illogical to run up and down on green grass, using energy,
instead of saving it.
-- Spock, "Shore Leave", stardate 3025.2
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Button event calls Leave/Enter

2019-05-13 Thread Michael Lange
Hi,

On Mon, 13 May 2019 17:32:10 -
mkie...@web.de wrote:

> Hello,
>
> >very strange. Maybe an issue with the WM? Do you also use Xfce? Did you
> >(or Vasilis) try a different WM?
>
> To add some data about used WMs, not reproducible on:
> Python 3.5.3 (some small tkinter patches)
> tcl/tk 8.6.6
> debian stretch
> ctwm

oh, I forgot to mention earlier, not reproducible here on Debian Stretch
with IceWM.

Regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Power is danger.
-- The Centurion, "Balance of Terror", stardate 1709.2
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Button event calls Leave/Enter

2019-05-13 Thread Michael Lange
On Mon, 13 May 2019 10:27:12 +0200
Paul Malherbe  wrote:

> Yes, definitely seems to be an xfce thing. Tried with gnome and worked
> fine.

Good to know that. Unfortunately this does not help much with the OP's
question :-(
Maybe some property of the event could be checked, if there is a
difference betwen a "real" and a "fake"  or  event.

Regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Sometimes a feeling is all we humans have to go on.
-- Kirk, "A Taste of Armageddon", stardate 3193.9
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Button event calls Leave/Enter

2019-05-13 Thread Michael Lange
Hi,

On Mon, 13 May 2019 08:19:58 +0200
Paul Malherbe  wrote:

> Same happens on Ubuntu 18.04 with python 2.7.15/3.6.7 and tcl/tk 8.6.8

very strange. Maybe an issue with the WM? Do you also use Xfce? Did you
(or Vasilis) try a different WM?

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

"What happened to the crewman?"
"The M-5 computer needed a new power source, the crewman merely
 got in the way."
-- Kirk and Dr. Richard Daystrom, "The Ultimate Computer",
   stardate 4731.3.
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Button event calls Leave/Enter

2019-05-10 Thread Michael Lange
Hi,

On Thu, 9 May 2019 07:58:42 +
Vasilis Vlachoudis  wrote:

> Hi all,
>
> I've just realized that the mouse click  event generates as
> well a  followed by  event before.

what system are you using and which version of Tcl/Tk?
I cannot reproduce that behavior here (Debian, Tk 8.6.6).

Regards

Michael

> With the program below, if one clicks in the frame
> you get the messages printed
> Leave event
> Enter event
> Button1 pressed
> Which I don't understand the reasoning behind. However it generates
> a problem to my application since I have some actions that are binded
> with the Leave event and when the button1 handler is called the program
> has already altered some structures.
> Is there a way forbit the calls to Leave/Enter before the Button1?
>
> Many thanks in advance
> Vasilis
>
> import tkinter as tk
> def enter(event): print("Enter event")
> def leave(event): print("Leave event")
> def button1(event): print("Button1 pressed")
>
> root = tk.Tk()
> frame = tk.Frame(root, bg="Yellow",
> takefocus=False,
> width=600, height=400)
> frame.pack(fill=tk.BOTH, expand=tk.YES)
> frame.bind("", enter)
> frame.bind("", leave)
> frame.bind("", button1)
> root.mainloop()
>



.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Virtue is a relative term.
-- Spock, "Friday's Child", stardate 3499.1
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] ttk.Treeview: coloring rows using tags doesn't work with Python 3.7.3

2019-04-29 Thread Michael Lange
Hi,

On Mon, 29 Apr 2019 13:16:50 +0200
Sibylle Koczian  wrote:

> Hello,
>
> the following script shows a Treeview with names and country codes of
> some towns in Germany. Towns with country code "HE" or "BY" should be
> shown with coloured background, in the case of "BY" additionally with
> white text.
>
> This works using Python 3.5 or 3.6. I seem to remember that it worked
> with earlier versions of Python 3.7, but that's not certain. Using
> Python 3.7.3 all the entries have white background and black text.
> Opening an entry with Enter or double click shows the name of the town
> in the Entry field, together with the country name, if the row has the
> tag for HE or BY. So the entries have the tags they should, but the
> color doesn't change.
>
> Changing the font of an entry using tags does work.
>
> All of these Python versions come with tcl/tk version 8.6, but I don't
> know the patch numbers, they probably changed. The official
> documentation for tkinter and for tcl/tk seems to show that the script
> is correct. I can see no hint of recent changes in the use of tags,
> tag_configure and the options usable with tags.

just a shot into the dark:

maybe the problem is not at all how the treeview handles tags, but how Tk
handles named colors? Did you try to use hex color specs like '#d9d9d9'
instead of 'darkgray' or 'lightgreen'? According to
https://www.tcl-lang.org/man/tcl8.6/TkCmd/colors.htm
there should be "dark gray" and "LightGreen", but maybe your version of
Tk somehow fails to treat the color names case-insensitive resp.
"space-insensitive".

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Space: the final frontier.  These are the voyages of the starship
Enterprise. Its five-year mission: to explore strange new worlds; to seek
out new life and new civilizations; to boldly go where no man has gone
before.
-- Captain James T. Kirk
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] ttk.Label unicode characters

2019-01-21 Thread Michael Lange
Hi again,

sorry for my somewhat disjointed replies :)

On Sun, 20 Jan 2019 20:30:35 +0100
Michael Lange  wrote:

(...)
> l = ttk.Label(root)
> l.grid()
> l.tk.eval(l._w + ' configure -text "Test \U0001d306 String"')
>
> there is actually some character displayed which looks similar to this
> one: https://www.compart.com/en/unicode/U+1D306 , which I found rather
> surprising since with Tcl I get only a placeholder. The same happens
> when I replace your unicode character with the smiley \U0001f600 they
> used in the page I referred to before. tk.eval appears to do some magic
> here.

tinkering a bit more I found another solution which seems more obvious,
however I was not able to get this working with Python3. With Python2
when I do the following:

from Tkinter import *
import ttk

root = Tk()
l = ttk.Label(root)
l.pack(padx=40, pady=40)

s = u'Test \U0001d306 String'
s1 = s.encode('utf-8')
l.configure(text=s1)

root.mainloop()

the label's text looks like expected. Maybe that is just the same "magic"
that tk.eval applies. It does not seem to be that easy with Python3
though, apparently I missed some of the subtleties with Python3's unicode
handling mechanisms.

Regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

The joys of love made her human and the agonies of love destroyed her.
-- Spock, "Requiem for Methuselah", stardate 5842.8
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] ttk.Label unicode characters

2019-01-20 Thread Michael Lange
Ooops, looks like I might need to correct myself.

On Sun, 20 Jan 2019 20:06:18 +0100
Michael Lange  wrote:

(...)
> according to
> https://groups.google.com/forum/#!topic/comp.lang.tcl/OJqYYzCgKQo
> there is some work in progress with Tcl, otoh even if you install the
> latest Tcl/Tk 8.7 it might be difficult to get past this TclError which
> seems to be hardcoded into Tkinter (with Tcl I don't get any error here,
> just a placeholder where the unicode character should be).

when I try to change your example a bit, like this:

l = ttk.Label(root)
l.grid()
l.tk.eval(l._w + ' configure -text "Test \U0001d306 String"')

there is actually some character displayed which looks similar to this
one: https://www.compart.com/en/unicode/U+1D306 , which I found rather
surprising since with Tcl I get only a placeholder. The same happens when
I replace your unicode character with the smiley \U0001f600 they used in
the page I referred to before. tk.eval appears to do some magic here.

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

No more blah, blah, blah!
-- Kirk, "Miri", stardate 2713.6
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] ttk.Label unicode characters

2019-01-20 Thread Michael Lange
Hi,

On Sat, 19 Jan 2019 20:07:07 -0500
Ben  wrote:

> Hi,
>
> Is there any way to make a Label display every Unicode character, or
> are we just stuck until Tcl/Tk fully supports all of unicode?
>
> Here's my example code:
> import tkinter as tk
> from tkinter import ttk
> root = tk.Tk()
> ttk.Label(root, text='Test \U0001d306 String').grid(row=0, column=0)
> root.mainloop()
>
> And the exception:
> _tkinter.TclError: character U+1d306 is above the range (U+-U+)
> allowed by Tcl
>
> System: Linux, Python 3.6.7, Tk 8.6
>
> Is there anything I can do to be able to display that character?

according to
https://groups.google.com/forum/#!topic/comp.lang.tcl/OJqYYzCgKQo
there is some work in progress with Tcl, otoh even if you install the
latest Tcl/Tk 8.7 it might be difficult to get past this TclError which
seems to be hardcoded into Tkinter (with Tcl I don't get any error here,
just a placeholder where the unicode character should be).

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

On my planet, to rest is to rest -- to cease using energy.  To me, it
is quite illogical to run up and down on green grass, using energy,
instead of saving it.
-- Spock, "Shore Leave", stardate 3025.2
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] how do I pass variables when binding to a widget?

2019-01-10 Thread Michael Lange
Hi Chris,

On Thu, 10 Jan 2019 15:13:12 +1100
Chris Roy-Smith  wrote:

> Hi
> System:   Linux,
> Python Version:   3.6.7
> 
> I am trying to learn how to bind to a widget, and process the contents 
> of the bound widget
(...)
> I get the following traceback:
> 
> Traceback (most recent call last):
>File "./bind.py", line 19, in 
>  first.bind("", NewAge(first.get()))
>File "./bind.py", line 7, in NewAge
>  futureAge = start + 5
> TypeError: must be str, not int

here for some reason the traceback looks slightly different:

~$ python3 test4.py

Traceback (most recent call last):
  File "test4.py", line 24, in 
first.bind("", NewAge(first.get()))
  File "test4.py", line 19, in NewAge
futureAge = start + 5
TypeError: Can't convert 'int' object to str implicitly

What happens becomes a bit more obvious if you change your code a bit
like this:

  (...)
  first=Entry(master)
  first.grid(row=0, column=1)
  # add a default value in the first entry
  first.insert('end', 25)
  calculated = Entry(master)
  calculated.grid(row=1, column=1)
  first.bind("", NewAge(first.get()))
  (...)

Then the traceback here looks like:

~$ python3 test4.py
25
Traceback (most recent call last):
  File "test4.py", line 21, in 
first.bind("", NewAge(first.get()))
  File "test4.py", line 8, in NewAge
futureAge = start + 5
TypeError: Can't convert 'int' object to str implicitly

So, what happens is, that as soon as your bind() function call is
processed the NewAge() function is called with first.get() as argument.
Since first.get() will always return a string, trying to add an integer
value will of course cause an error.

To fix this you need to change the call to bind(), so that the second
argument is the function NewAge itself, not a *call* to that function, as
in:

  first.bind("", NewAge)

After the binding has been applied, each time the  event occurs
on that widget, the NewAge function will be called by tkinter with an
Event object as argument. So the definition of the NewAge function might
for example look like this:

def NewAge(event):
try:
futureAge = int(event.widget.get()) + 5
calculated.delete(0,END)
calculated.insert(0,futureAge)
except ValueError:
event.widget.bell()

If you want to learn more about Events (and tkinter in general), John
Shipman's excellent tkinter reference is an invaluable source of
knowledge:

https://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html
About tkinter Events:
https://infohost.nmt.edu/tcc/help/pubs/tkinter/web/events.html

And of course you are always welcome here to ask further questions.

I hope this helps.

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

... bacteriological warfare ... hard to believe we were once foolish
enough to play around with that.
-- McCoy, "The Omega Glory", stardate unknown
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Event debugging

2018-12-17 Thread Michael Lange
Hi,

On Mon, 17 Dec 2018 07:52:52 +
Vasilis Vlachoudis  wrote:

> Hi all
> 
> in my application there is one listbox which has a bind
> ("",...) strangely enough under some OS the Double-1 is not
> working. For example in Fedora with KDE it works ok but not on Ubuntu
> with XFCE.
> 
> Is there a way to debug the events? I believe that some other
> widget is intercepting the Button-1 and somehow it blocks the
> Double-1

did you try to add a print(event.widget) to the callback?
Can you post a simple code example that exhibits the problem?

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

It is necessary to have purpose.
-- Alice #1, "I, Mudd", stardate 4513.3
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Text editing and tags...

2018-12-12 Thread Michael Lange
Hi,

On Wed, 12 Dec 2018 10:32:24 +
Vasilis Vlachoudis  wrote:

(...)
> What it is the advantage of using the
> txt.tk.call('tk::TextInsert', txt._w, event.char)# borrowed from
> text.tcl instead of txt.insert()?
> 

actually I do not know if there is any difference, I just supposed there
might be. The apparently more low-level tk::TextInsert is exactly what
the Text widget does on KeyPress events, so when I set up that example I
just copied it. Of course that snippet was just a "quick shot", for all I
know insert() may or may not do exactly the same :-)

Best regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

A father doesn't destroy his children.
-- Lt. Carolyn Palamas, "Who Mourns for Adonais?",
   stardate 3468.1.
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Text editing and tags...

2018-12-11 Thread Michael Lange
Hi Vasilis,

On Tue, 11 Dec 2018 13:45:10 +
Vasilis Vlachoudis  wrote:

> Hi all,
> 
> Considering the following code, it creates a Text() and adds the word
> "Red" with tag "red" and "Normal" without  afterwords without any tag.
> If you click the cursor in between the two letters d|N from (Red"d" and
> "N"ormal) and you start typing, the newly inserted text will be black
> without out any tag associated. Is there a way to change this behavior
> like the word processing editor where the end of a tag is inclusive
> that if you start typing at the end of the tag it will assume that is
> inside the tag-range and not outside?

so far as I can see there is no built-in way to achieve this. Maybe you
can try to override the default Tk event handlers of the Text widget.
For starters I set up a very basic example of a modified KeyPress event
handler:

##
import tkinter as tk
root=tk.Tk()
txt = tk.Text(root)
txt.pack(fill='both', expand=1)
txt.tag_configure("red", foreground="Red")
txt.insert('end',"Red", 'red')
txt.insert('end',"Normal")

def on_key_press(event):
ins = txt.index('insert')
if event.char and not ('\n' in event.char or '\r' in event.char or '\b' in 
event.char):
txt.tk.call('tk::TextInsert', txt._w, event.char)# borrowed from 
text.tcl
l, i = str(ins).split('.')
if int(i) > 0 and 'red' in txt.tag_names('%s.%d' %(l, int(i)-1)):
txt.tag_add('red', ins)
return('break')

txt.bind('', on_key_press)

root.mainloop()
##

I guess this is not perfect though, and you will probably also want
handlers for copy-and-paste'ing text.

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

It is a human characteristic to love little animals, especially if
they're attractive in some way.
-- McCoy, "The Trouble with Tribbles", stardate 4525.6
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Text drag

2018-11-04 Thread Michael Lange
Hi,

On Sun, 4 Nov 2018 19:37:29 +
Vasilis Vlachoudis  wrote:

(...)
> #1. However I cannot get rid of the #1. I've tried to subclass the
> #DndHandler()
> especially the on_motion() method to delete the text anchor (dirty
> hack) after looking at the text.tcl  as well deleting the selection and
> calling the CancelRepeat to avoid the auto-scrolling, but nothing
> worked ok. Is there a way to tell the Text() to stop the selection?

I think you could add something like this to DnDHandler.__init__() :

def _return_break(widget, event):
return 'break'
self._id = widget.bind('')
widget.bind('', _return_break)

which should remove the motion-selection binding and then restore it after
the dnd operation has finished by adding

self.initial_widget.bind('', self._id)

to the end of DnDHandler.finish() (untested however).

Regards

Michael





.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

"The combination of a number of things to make existence
worthwhile." "Yes, the philosophy of 'none,' meaning 'all.'"
-- Spock and Lincoln, "The Savage Curtain", stardate
5906.4
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] real and platform independent maximizing a window

2018-03-30 Thread Michael Lange
Hi,

On Fri, 30 Mar 2018 01:15:59 +0200
 wrote:

> When looking around about the question how to "maximize a window" with
> Tkinter there are two approaches.
> 
> 1.
> Using wm_state('-zoomed', True).
> Problem: Not working on all platforms. e. g. "-zoomed" is not allowed
> on Debian unstable with XFCE on Python3.6 Tkinter 8.6
> 
> 2.
> Compute the screen resolution or maxsize() and set it manually. This
> doesn't work also. The size doesn't fit exact and the "maximize" button
> on the top right corner is still available - should be transformed to a
> "normal size" button because the current state is "maximized".
> 
> Isn't there a platform independent way to real(!) maximize a window
> with Tkinter? If not is there a ticket in the bug tracker about it?

unless I missed some recent development, there is no such way.
I don't think this a bug, but rather a "missing feature" in Tk (if one
wants to put it that way).
Maybe one major problem here is that usually you don't really want a
maximized window to occupy the entire screen, but only the part of the
screen that is not covered by system panels. With X11 there are plenty of
WMs / DEs to deal with, and it is most likely hard to
satisfy them all. But I don't know for sure, that is just a guess.

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Military secrets are the most fleeting of all.
-- Spock, "The Enterprise Incident", stardate 5027.4
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


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

2018-03-28 Thread Michael Lange
Hi,

On Wed, 28 Mar 2018 13:07:54 -0700
Nam Nguyen  wrote:

> This happens in Tcl/Tk too. I'll follow up with the Tk folks and come
> back if there's any fix or workaround.

Sure, I never doubted that it has nothing particularly to do with Tkinter.

Regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

This cultural mystique surrounding the biological function -- you
realize humans are overly preoccupied with the subject.
-- Kelinda the Kelvan, "By Any Other Name", stardate
4658.9
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


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

2018-03-28 Thread Michael Lange
Hi,

On Wed, 28 Mar 2018 01:18:50 +
Nam Nguyen  wrote:

> Is my code out of whack or is it "standard" enough to your seasoned
> eyes? Is there any guess as to a fix to this flickering, be it with my
> code, or Tk itself?

of course you could address the "mouse over widget" issue with something
like

  b1 = tk.Button(f_1, text='Frame 1', font=my_font)
  b1.pack(expand=True, fill=tk.BOTH)
  bg = b1.cget('background')
  b1.configure(activebackground=bg)
  f_2 = tk.Frame(root)
  tk.Button(f_2, text='Frame 2'[::-1], font=my_font,
   activebackground=bg).pack( expand=True, fill=tk.BOTH)

For the flicker that remains, I don't think there is much one can do
about it. If my assumption that it comes simply from the redrawing
operation is correct, I am afraid that there is no remedy (at least none
that I am aware of). Here it is barely visible but this might depend on
the speed of the system. When Brian says that he does not notice any
flicker at all, that might just be because his machine is faster than
mine. Of course there is still a chance that I have been missing
something.

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Our way is peace.
-- Septimus, the Son Worshiper, "Bread and Circuses",
   stardate 4040.7.
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


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

2018-03-27 Thread Michael Lange
Hi,

On Tue, 27 Mar 2018 13:27:06 -0700
Nam Nguyen via Tkinter-discuss  wrote:

> I'm running i3-wm on Debian and this code tends to flicks more when I
> have my mouse over the buttons.
> Nam

I see some flicker here, too. The additional flicker when the mouse
hovers over the window is apparently due to the  event that occurs
after the widget was packed, which switches the button's background to
the activebackground color. The (here rather tiny) flicker with the mouse
outside the window is maybe only due to the time Tk needs to redraw the
window.
This effect can be observed more closely when you set the background
color of one button for example to "red" and to "green" for the other.
You will get much more flicker all of a sudden.

Best regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Witch!  Witch!  They'll burn ya!
-- Hag, "Tomorrow is Yesterday", stardate unknown
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


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

2018-03-26 Thread Michael Lange
Hi,

On Mon, 26 Mar 2018 14:41:28 -0700
Nam Nguyen  wrote:

> On this note, is setting/getting variables (StringVar, IntVar etc)
> considered GUI action? Why, or why not?
> Thanks!
> Nam

as Brian already pointed out, when setting/getting those varaible's
values Tcl commands are involved. A less technical but (maybe) more
obvious explanation may be that setting the variable value may change
directly for example the string displayed in a Label widget. Considering
this I believe it is rather evident that it actually is gui action.

Best regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

You go slow, be gentle.  It's no one-way street -- you know how you
feel and that's all.  It's how the girl feels too.  Don't press.  If
the girl feels anything for you at all, you'll know.
-- Kirk, "Charlie X", stardate 1535.8
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


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

2018-03-26 Thread Michael Lange
Hi,

On Mon, 26 Mar 2018 12:54:20 -0700
Nam Nguyen via Tkinter-discuss  wrote:

> This is where my confusion comes from, actually ;). Python is single
> threaded (from the OS point of view). When I create the TCL
> interpreter, it is also created in the same thread that runs the Python
> interpreter. So regardless of how many Python threads (threading
> module), they all should belong to this same OS thread, should they not?

I am not an expert on this, but I don't think so. At least here when I
run a Tkinter app using threads (on linux) I see three threads in top,
each with a different pid.
And I am quite sure that I have seen strange things happen, iirc seemingly
unpredictable, when the rule of thumb "run Tk only from the main thread
and don't touch it from any child thread" was not observed. Some times
such code *seemed* to work though, which I believe makes it even more
dangerous, since it seems you can never know what (and when) will hit you.
So my recommendation is to just either stick with that "rule of thumb" or
else try the aforementioned thread-safe tkinter version.

Best regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

On my planet, to rest is to rest -- to cease using energy.  To me, it
is quite illogical to run up and down on green grass, using energy,
instead of saving it.
-- Spock, "Shore Leave", stardate 3025.2
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] configure command

2018-03-07 Thread Michael Lange
Hi,

On Wed, 7 Mar 2018 13:46:40 +
adil gourinda  wrote:

> For the last time, what is the parameter's name that accepts option's
> name as a string:
> 
> instance.configure(?!?!="option")
> 
> I hope I was clear this time.

ok, I got it now :)
As Brian pointed out, there is no literal parameter name here in Python,
however (to make things a bit more confusing :) technically speaking you
can use "cnf" as keyword-parameter here (although "cnf" is usually
supposed to be a {"option":"value"} dict), so e.g.:

  >>> widget.configure('bd')
  ('borderwidth', 'borderWidth', 'BorderWidth', , 0)

is equal to

  >>> widget.configure(cnf='bd')
  ('borderwidth', 'borderWidth', 'BorderWidth', , 0)


Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

You can't evaluate a man by logic alone.
-- McCoy, "I, Mudd", stardate 4513.3
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Fixed ratio split screen geometry manager

2018-03-06 Thread Michael Lange
Hi,

On Tue, 6 Mar 2018 09:57:01 -0800
Nam Nguyen  wrote:

> Hi,
> 
> I'm looking for a fixed ratio 2-pane geometry manager.
> 
> I tried PanedWindow but it does not have any option for me to specify
> the ratio of the children.
> 
> What I'm looking for is a geometry manager/container that splits its
> space into two for the children. The children can grow only in their
> own spaces. The children can come and go, but the parent container
> should maintain that 2-pane split with the same ratio.
> 
> Where should I look into?

in case you do not need the PanedWindow's resize handle, you might
want to have a look at the Grid geometry manager's uniform and weight
options to the grid_columnconfigure() and grid_rowconfigure() commands.

Another option might be to have a look at the Place geometry manager,
especially the relheight and relwidth options. Using for example 
relheight=0.5 will make the widget always occupy 50% of the parent
widget's height.

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

The sight of death frightens them [Earthers].
-- Kras the Klingon, "Friday's Child", stardate 3497.2
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] configure command

2018-03-06 Thread Michael Lange
Hi,

On Tue, 6 Mar 2018 16:31:23 +
adil gourinda  wrote:

> In your example, is "width" a positional argument or a
> positional-keyword argument (and if it is what is the parameter's
> name) ?

Not sure what you mean by that; I would tend to say the parameter's name
is "width" ;)

At
https://www.tcl.tk/man/tcl8.4/TkCmd/panedwindow.htm#M33
this is explained in more detail.

Regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Earth -- mother of the most beautiful women in the universe.
-- Apollo, "Who Mourns for Adonais?" stardate 3468.1
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] configure command

2018-03-05 Thread Michael Lange
Hi,

On Sun, 4 Mar 2018 23:26:56 +
adil gourinda  wrote:

> [cid:132f79be-dacf-4e7a-b0b1-94f5411d267b]
> By this picture I tried to explain the translation of "configure"
> command from Tcl to Python configure() method.
> 
> For the (1) and (3) cases the python's syntax is clear.
> 
> But for the (2) case where in Tcl I need to write only the option's
> name without value, what is its equivalent in Python (when the
> parameter's name is an argument)?; I tried the syntax in the picture
> and it works but what make things more difficult is when there is
> another parameter before "option" (ex :PanedWindow.paneconfigure).
> 
> Thanks for your attention

actually that is quite straightforward, as a little toying around reveals:

First a simple example in Tcl:

$ wish
% panedwindow .pw
.pw
% pack .pw
% text .pw.t
.pw.t
% .pw add .pw.t
% .pw paneconfigure .pw.t -width
-width {} {} {} {}
%

Now the same in Python:

$ python
Python 2.7.13 (default, Nov 24 2017, 17:33:09) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from Tkinter import *
>>> root = Tk()
>>> pw = PanedWindow(root)
>>> pw.pack()
>>> t = Text(pw)
>>> pw.add(t)
>>> pw.paneconfigure(t, 'width')
('width', '', '', '', '')
>>>

So you see, the paneconfigure command works exactly the same in Python as
it does in Tcl.

Regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Dismissed.  That's a Star Fleet expression for, "Get out."
-- Capt. Kathryn Janeway, Star Trek: Voyager, "The Cloud"
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] clipboard and bytes

2018-03-02 Thread Michael Lange
Hi,

Vasilis Vlachoudis  wrote:

> I works within the same process.
> When I try to launch it twice, so I can have clipboard exchange between
> different processes
> 
> I get the following exception:
> Traceback (most recent call last):
>   File "/usr/lib/python3.6/tkinter/__init__.py", line 1702, in __call__
> return self.func(*args)
>   File "foo.py", line 41, in paste
> res = root.tk.call(clip)
> _tkinter.TclError: invalid command name "139879786444744cp"

oh sure, I did not think about *that* :)
This is not going to work of course with two separate program instances.

> I did something else.
> I've used the binascii.b2a_hex() and a2b_hex() functions
> to convert the bytes() to a hex string and the reverse (double in size,
> and a useless UTF-8 conversion, encode/decode) 
> This way it works but not a clean approach,
> since I am copying in the clipboard binary data in a form of ascii.

Actually I believe, if you got it working, that it is probably the most
"clean" approach, at least as long as you stay within Tk; I guess that
other software might only receive "junk data" from the clipboard, though.

> Is there a way to create a new mime format and advertise
> the format somehow in the clipboard?

Quoting "man clipboard" again:

  " Type specifies the form in which the selection is to be returned (the
  desired ``target'' for conversion, in ICCCM terminology), and should be
  an atom name such as STRING or FILE_NAME; see the Inter-Client
  Communication Conventions Manual for complete details. Type defaults to
  STRING.

  The format argument specifies the representation that should be used to
  transmit the selection to the requester (the second column of Table 2 of
  the ICCCM), and defaults to STRING.(...)

  The format argument is needed only for compatibility with clipboard
  requesters that do not use Tk. If the Tk toolkit is being used to
  retrieve the CLIPBOARD selection then the value is converted back to a
  string at the requesting end, so format is irrelevant."

So I guess that the answer is probably "yes" here, but it sounds to me
like a non-trivial task that might require a considerable amount of
extra-investigation. 

> I've been reading and debugging a bit what firefox is doing and how the
> selection is treated. I couldn't find anywhere how to handle binary
> data, but firefox when you copy an image it creates customs mime types
> like image/png that contain the data in a form '0x39 0xf7 0xb8 0x8f
> 0xff ...'

Probably they are doing something of that ICCCM compliant things, but I
really don't know anything about that.

> Now I don't know if it is tk/tcl or _tkinter that makes this
> interpretation or the data are really ascii written in hex format, but
> I think even like this it can work for me.

I think it is surely tcl/tk that does it, tkinter only calls tk's
clipboard commands. However tkinter in some situations *might* do some
"mangling" to the data that tk returns (e.g. in the example from my
previous post, when the "embedded" helper func would return a list,
self.tk.call() would turn this into a tuple). 

Best regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Fascinating, a totally parochial attitude.
-- Spock, "Metamorphosis", stardate 3219.8
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] clipboard and bytes

2018-02-28 Thread Michael Lange
On Wed, 28 Feb 2018 20:42:51 +0100
Michael Lange <klappn...@web.de> wrote:

(...)
> So at least this primitive seems to work. Maybe you can use this
> technique to achieve what you want.

Or maybe this slightly modified example comes closer to what you are
looking for:

from tkinter import *

root = Tk()

def copy(string):
def cp():
return string
copyfunc = (root.register(cp))
return(copyfunc)

root.clipboard_clear()
root.clipboard_append(copy(b'foobar'), type='foo')

def paste(ev):
clip = root.clipboard_get(type='foo')
res = root.tk.call(clip)
print('->', res, type(res))

root.bind('', paste)
root.mainloop()



Regards
 
Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

"... freedom ... is a worship word..."
"It is our worship word too."
-- Cloud William and Kirk, "The Omega Glory", stardate
   unknown
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] clipboard and bytes

2018-02-28 Thread Michael Lange
Hi,

On Wed, 28 Feb 2018 10:59:31 +
Vasilis Vlachoudis  wrote:

(...)
> In python3 Pickler requires a byte stream so I replaced all StringIO()
> to BytesIO() and the targets with bytes target1 = b""
> Copying to clipboard work ok (or I believe so)
> Pasting, clipboard_get() returns a str not bytes and the Unpickler
> fails. Also If I try to encode("UTF-8") the clip data also it fails.

according to man clipboard it is possible create custom data types to be
stored in the tk clipboard:
  "You can put custom data into the clipboard by using a custom -type
  option. This is not necessarily portable, but can be very useful. The
  method of passing Tcl scripts this way is effective, but should be mixed
  with safe interpreters in production code."

I set up a (rather useless) example how this can be done:

##
from tkinter import *

root = Tk()

def copy(string):
def cp():
return 666
copyfunc = (root.register(cp))
return(copyfunc)

root.clipboard_clear()
root.clipboard_append(copy('foobar'), type='foo')

def paste(ev):
clip = root.clipboard_get(type='foo')
res = root.tk.call(clip)
print('->', res, type(res))

root.bind('', paste)
root.mainloop()
#

When I run this script and hit F1 I get the following output:

  $ python3 test5.py
  -> 666 

So at least this primitive seems to work. Maybe you can use this
technique to achieve what you want.

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Without followers, evil cannot spread.
-- Spock, "And The Children Shall Lead", stardate 5029.5
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] multicolumn list/tree with images

2018-02-18 Thread Michael Lange
Hi,

On Sun, 18 Feb 2018 13:53:27 +0100
 wrote:

(...)
> No docu about tix. There is only tcl code. No Python. The pydoc docu
> doesn't help, too. I don't see how to add columns to any of the listbox
> alike widgets or if is is even possible.

in debian there is a demo in the tix-dev package
at /usr/share/doc/tix/examples/tixwidgets.tcl where you can have a look
at the features of the tix widgets. But maybe you are right and tix
simply does not offer something of the kind you are looking for.

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Schshschshchsch.
-- The Gorn, "Arena", stardate 3046.2
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] multicolumn list/tree with images

2018-02-16 Thread Michael Lange
On Fri, 16 Feb 2018 22:06:58 +0100
 wrote:

> Dear Michael,
> 
> thank you very much for your valuable reply.
> 
> > there does not seem to be a way to
> > make only the "checkbutton" icon sensitive to mouse clicks
> 
> The event object have the exact coordinates of the click position.
> Based on them you can identify the row and column. Quick & Dirty
> example
> 
> def on_click(event):
> iid = event.widget.selection()[0]
> col = event.widget.identify(component='column',
> x=event.x, y=event.y)
> print('iid: {} column: {}'.format(iid, col))
> 

Yes, but that column includes a few pixels of white space on the left of
the checkbox and a few pixels of space (including the space the "active"
rectangle takes) to the checkbox's right. At least I could not find a way
to work around this without having to try something rather fancy with
absolute screen coordinates which I thought would not be worth the effort
and besides bear potential for bugs.

> 
> > There are several third party solutions available, though.
> 
> I know. But I had some problems with their documentation, missing
> support channels, inactive community, unclear project status, ...
> 
> > TkinterTreectrl is a wrapper for the tktreectrl tcl extension
> > ...
> > https://sourceforge.net/projects/tktreectrl/
> > https://sourceforge.net/projects/tkintertreectrl/
> 
> What is the difference compared to tkinter.Treeview?
> What is the difference between your two links? Which one is more active
> and up to date? There is also a fork on GitHub where I opened an Issue
> about project status
> https://github.com/apnadkarni/tktreectrl/issues/1
> No examples no documentation.

To learn about the difference between the ttk.Treeview and the tktreectrl
widget I would like to be able to point you to their web page, but
unfortunately sf still appears to be in service. There is an archived
page available at:
https://web.archive.org/web/20170301130644/http://tktreectrl.sourceforge.net/

Just look at the screenshots and you will get an idea about how much more
capable this widget is than the ttk Treeview.
The difference between the two links is, that *tktreectrl* is the tk
extension library (written in C, windows binaries are available on the sf
download site, linux binaries included in most recent distributions) and
*tkintertreectrl* is a Python wrapper module I wrote for it (both
Python2 and -3). The docs on sf are of course currently down with the rest
of their pages, but are included in the download, plus a few very simple
demos. In case of questions you can always ask me :)

> 
> > able to do this, like tablelist and maybe tktable, you can look at
> > this archived page for more information and download links:
> > 
> > https://web.archive.org/web/20140412080251/http://tkinter.unpythonic.net:80/wiki/Widgets
> 
> Very important link - good to have the archive!
> 
> I checked the links: Some dead, some unclear about project status,
> features, screenshots, docu. I wrote some mails, issues and bug-tickets
> to be clearer in this points.
> 
> "TkTable"
> https://sourceforge.net/p/tktable/bugs/318/

I guess I could answer what you asked there :)
The last release was made in 2008. I bet it still works :)

> 
> Very interesting sounds the "The Multi-Column Listbox and Tree Widget
> Package Tablelist 6.0" where screenshots are available, too.
> 
> But it is pure Tcl code. I don't know how to use that with Python3.
> There is some quick and dirty code around on the web. But no official
> supported or infos about how much it fits to the Tcl code. No
> repository or support channel.

Kevin Walzer's python wrapper for tablelist is available here:
https://web.archive.org/web/20150920011432/http://tkinter.unpythonic.net/wiki/TableListWrapper

Looks like Python2 only, but it shouldn't be a problem to adapt it to
Python3. Personally I never used it, but I have been hearing good things
about it. I think Kevin probably still reads the list, so if you ask
questions about it here there might be a good chance to get help.

> 
> Pmw megawidgets
> 
> Website currently offline. No docu, no examples, no screenshots.

There is actually excellent documentation about Pmw on their page and
will hopefully soon be available again once sf have restored their
content. Probably downloads will still work, and they include the
documentation. However, unless something new showed up recently there is
no multi colomn listbox widget with icon support included.

> 
> > Finally there seems to be a tix.TList widget which might be able to do
> > what you want, though I never used it myself, see
> > https://docs.python.org/3/library/tkinter.tix.html
> The docu is currently offline.

Seems like right now we are learning something about the bad side effects
of monopoly structures... :)

> Don't know how to use or if it fit my
> needs. The little words about tix in the official Python3 

Re: [Tkinter-discuss] listdir

2018-02-16 Thread Michael Lange
Hi,

On Fri, 16 Feb 2018 09:51:33 +
Vasilis Vlachoudis  wrote:

> When I run your program
> 
> Download$ python codec.py 
> utf-8
> Download$ LC_ALL=C python codec.py 
> ansi_x3.4-1968
> Download$ LC_ALL=en_US.UTF-8 python codec.py 
> utf-8
> 
> it seems that python properly recognizes the LC_ALL setting

maybe some other environment variable causes confusion, it seems like
LC_CTYPE can cause problems, AFAIR that's why it's overridden in my
function call.
The following issue I found at bugs.python.org talks about this (not the
same as your problem, but somehow similar looking; seems like even a
terminal program can be the culprit :)

https://bugs.python.org/issue18378

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Sometimes a feeling is all we humans have to go on.
-- Kirk, "A Taste of Armageddon", stardate 3193.9
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] listdir

2018-02-16 Thread Michael Lange
Hi,

On Fri, 16 Feb 2018 08:49:01 +
Vasilis Vlachoudis  wrote:

> Thank you Michael,
> 
> my locale is UTF-8 when I get the error
> 
> $ locale
> LANG=en_US.UTF-8
> LANGUAGE=en_US.UTF-8
> LC_CTYPE="en_US.UTF-8"
> ...
> LC_ALL=en_US.UTF-8

ok. Don't know if it is possible that there is something in the configuration
that stops python from properly detecting the system encoding? Some ten
years ago (while using Python 2.3 :) I wrote myself a function that tries
to detect the system encoding (see below); since it is so old some of the things
that function does may be obsolete now, but I still use it today in
a number of my projects and it still works. If you like you can run this
snippet as a test script and see what it says.
Of course it is also well possible that my guess was wrong and the problem
lies somewhere else.

Best regards

Michael

###
import codecs
import locale

def _find_codec(encoding):
# return True if the requested codec is available, else return False
try:
codecs.lookup(encoding)
return 1
except (TypeError, LookupError):
return 0

def _sysencoding():
# try to guess the system default encoding
# this is mainly stolen from IDLE's IOBinding.py
# thanks for guidance to Martin v. Loewis
locale.setlocale(locale.LC_CTYPE, "")# don't mess the numeric types here, 
we might replace the decimal point with a comma and break Tk!
try:
enc = locale.getpreferredencoding()
if enc and _find_codec(enc):
return enc
except AttributeError:
# our python is too old, try something else
pass
try:
enc = locale.nl_langinfo(locale.CODESET)
if enc and _find_codec(enc):
return enc
except AttributeError:
pass
# the last try
try:
enc = locale.getdefaultlocale()[1]
if enc and _find_codec(enc):
return enc
except ValueError:
pass
# aargh, nothing good found, fall back to ascii and hope for the best
print 'warning: unable to find usable encoding, using ascii.'
return 'ascii'

print(_sysencoding().lower())

###


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Vulcans believe peace should not depend on force.
-- Amanda, "Journey to Babel", stardate 3842.3
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Get height of a row in Treeview in Tkinter with Python3

2018-02-15 Thread Michael Lange
Hi,

On Tue, 13 Feb 2018 22:00:48 +0100
 wrote:

> X-Post: https://stackoverflow.com/q/48736168/4865723
> 
> I want to know how height (in pixel) is a row in a tkinter.Treeview.
> 
> I know how I can manipulate the height (see example below) with the
> styling mechanism. But I want to read it first - because it depends on
> the operating system, fonts, etc. And I couldn't find something in the
> style object I could read for this.
> 
> My goal is to modify the rowheight with a relative factor. e.g. 1,5 of
> the original height.

I never used the rowheight option myself, so I don't know for sure. I
figure that by default the rowheight is not set explicitely and thus the
widget will assign the required height for each row individually (for
example different sized icons might lead to different row heights);
probably when rowheight is explicitely given all rows will be the same
height, regardless of their contents (is this correct?).

Now, if you assume that in your case all rows have the same height,
I think using bbox(someitem)[3] should deliver the value you want (maybe
with one or two extra pixels added for borders). However if the heights of
the rows differ, this value might probably lead to rather disappointing
results :)

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Even historians fail to learn from history -- they repeat the same
mistakes.
-- John Gill, "Patterns of Force", stardate 2534.7
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] listdir

2018-02-15 Thread Michael Lange
Hi,

On Thu, 15 Feb 2018 10:24:10 +
Vasilis Vlachoudis  wrote:

> Hi all,
> 
> I know that it it is not related to tkinter, but I had troubles in
> submitting in the general python list.
> 
> I was trying to make my custom FileDialog to handle unicode filenames
> and I stuck with the following behavior (python v2.7)
> 
> #path = "/home/bnv/Download"
> path = u"/home/bnv/Download"
> for fn in os.listdir(path):
> print(fn,type(fn))
> fullpath = os.path.join(path, fn)
> 
> If the "path" is defined as unicode I get the following output and error
> (u'foo.py', )
> ('Gewu\xccrzhalter.Part1.nc', )
> Traceback (most recent call last):
>   File "foo.py", line 20, in 
> filename = os.path.join(path, fn)
>   File "/usr/lib/python2.7/posixpath.py", line 73, in join
> path += '/' + b
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xcc in position 5:
> ordinal not in range(128)
> 
> While if the "path" is defined as str. I get
> ('foo.py', )
> ('Gewu\xccrzhalter.Part1.nc', )
> 
> I don't understand why if the path is unicode the output of listdir is
> unicode the filenames containing only ascii and str for the file with
> the non-ascii character. While if the path is str, all output is in str

I think this is because with "foo.py" no UnicodeError occurs and so the
str->unicode conversion succeeds. 

I can only guess why that UnicodeError occurs though, this doesn't happen
here. When I do $ export LANG=C before starting the python interpreter
however I get this same error as you (by default I have UTF-8 here).
So I think maybe your system default encoding is set to something that
does not support the non-ascii character in the filename which causes the
problem. This might also explain why the default tk file dialogs do not
seem to work for you (they work well here with unicode filenames).
Just a guess, of course.

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

If a man had a child who'd gone anti-social, killed perhaps, he'd still
tend to protect that child.
-- McCoy, "The Ultimate Computer", stardate 4731.3
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] multicolumn list/tree with images

2018-02-15 Thread Michael Lange
Hi,

On Wed, 14 Feb 2018 01:26:20 +0100
 wrote:

> On 2018-02-14 01:14  wrote:
> > But I need images as values. I don't want to use column '#0' for
> > images. Images should appear in the second column for example.
> 
> A workaround would be to keep the '#0' column with the image.
> But I need to remove the tree space (some pixel on the left of the
> picture) because I don't need a tree. But show='headings' would remove
> the complete '#0' column with the image.
> 
> I need an image in each list row as small button. The user can use this
> as a flag to mark some rows.

I have a similar setup in one of my apps, where I use a "checkbutton"
image in col #0 so the user can select or deselect a list entry. It
works, but is not perfect, though: there does not seem to be a way to
make only the "checkbutton" icon sensitive to mouse clicks, so the
"checkbutton's" state changes even when the user clicks somewhere in col
#0 next to the icon. And the "active rectangle" appears only as a tiny
dotted rectangle between the icon and the text which is in col #1.
The setup I use, which apart from the above issues I think looks good
enough, is

treeview.configure(show=('tree', ), columns=('foobar',))
treeview.column('#0', width=35, stretch=0)

Best regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Live long and prosper.
-- Spock, "Amok Time", stardate 3372.7
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] multicolumn list/tree with images

2018-02-15 Thread Michael Lange
Hi,

On Wed, 14 Feb 2018 01:14:53 +0100
 wrote:

> I experimented with tkinter.ttk.Treeview and tkinter.Listbox on Python3.
> 
> I need a list widget with multiple columns (this could be Treeview).
> But I need images as values. I don't want to use column '#0' for
> images. Images should appear in the second column for example.
> 
> Tk itself has a treectrl. Maybe it is possible with it? But I don't
> know how to use this with Python3.
> 
> Maybe there are other third party solutions around?

with ttk.Treeview you can add images only to the first column.

There are several third party solutions available, though.
TkinterTreectrl is a wrapper for the tktreectrl tcl extension and
contains a multi column listbox class that can be set up to use images in
any column:
https://sourceforge.net/projects/tktreectrl/
https://sourceforge.net/projects/tkintertreectrl/
(seems like sf's project pages are down today, but downloads are
possible).

There are some other alternatives that I (being somewhat biased
towards the treectrl :) have never been using myself, which should be able
to do this, like tablelist and maybe tktable, you can look at this
archived page for more information and download links:

https://web.archive.org/web/20140412080251/http://tkinter.unpythonic.net:80/wiki/Widgets

Finally there seems to be a tix.TList widget which might be able to do
what you want, though I never used it myself, see
https://docs.python.org/3/library/tkinter.tix.html

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

You'll learn something about men and women -- the way they're supposed
to be.  Caring for each other, being happy with each other, being good
to each other.  That's what we call love.  You'll like that a lot.
-- Kirk, "The Apple", stardate 3715.6
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Listbox size

2018-02-14 Thread Michael Lange
Hi,

On Tue, 13 Feb 2018 17:11:47 -0700
Bob van der Poel  wrote:

> Getting closer :)
> 
> I asked the question wrongly. I need to determine the number of VISIBLE
> lines in the listbox.

Should be (as used in my previous example)

visible_lines = lb.nearest(lb.winfo_height()) - lb.nearest(0)

> 
> Using the .winfo_height() does return the height in pixels. Note: You do
> have to make the widget visible before doing this, otherwise you just
> get "1" returned. widget.update() works for this.

I don't think the widget must actually be "visible"; it is only when the
widget is initially created that the widget's dimensions are reported as
1*1 px. Calling update_idletasks() once after the widgets have been
created should be sufficient to work around this.

> 
> So, the next question is: what is the line size?

That is definitely not needed for what you want to accomplish.

> 
> Now, to make life much simpler :) I just played a bit and discovered
> that if I make the listbox visible BEFORE the selection, it
> automatically centers. So, my code now becomes:
> 
>self.lb.update()
>self.lb.select_clear(ACTIVE)   # needed to un-hilite existing
> selection self.lb.see(x)
>self.lb.activate(x)
>self.lb.select_set(x)
> 
> Easy. And I don't need to worry about the size of the box!

Here see() does not necessarily center the given index. It sometimes
appears near the top or the bottom of the list.
And that's just what the manpage promises:

" if the element is near one edge of the window then the listbox scrolls
to bring the element into view at the edge; otherwise the listbox scrolls
to center the element. "

> 
> Well, mostly. If the selection I want is already on the screen, then the
> box doesn't scroll to center. I think I can live with that.

Good, again that's exactly what the listbox's manpage promises :)
If you want exactly predictable behavior, I think you will have to use
yview() instead.

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

You humans have that emotional need to express gratitude.  "You're
welcome," I believe, is the correct response.
-- Spock, "Bread and Circuses", stardate 4041.2
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Listbox size

2018-02-13 Thread Michael Lange
On Wed, 14 Feb 2018 00:32:09 +0100
Michael Lange <klappn...@web.de> wrote:

(...)
> I guess
> this simple function is certainly not perfect (but maybe it is already
> good enough):

um, maybe that test() function should be slightly changed, like this
(although yview() does not seem to complain about negative indices):

def test(event):
i = 597
wd = event.widget
wd.selection_clear(0, 'end')
wd.selection_set(i)
wd.update_idletasks()
h1 = wd.winfo_height()
i1, i2 = wd.nearest(0), wd.nearest(h1)
index = i - (i2-i1)/2
if index < 0:
index = 0
wd.yview(index)

Best regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

It is necessary to have purpose.
-- Alice #1, "I, Mudd", stardate 4513.3
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Listbox size

2018-02-13 Thread Michael Lange
On Tue, 13 Feb 2018 17:19:44 -0600
Bryan Oakley  wrote:

(...)
> Another trick would be to get the index of the item at the 0th pixel
> location of the widget (eg: the_listbox.index("@0,0"), and another at
> the pixel location for the height of the widget (ie: by using the
> result of the winfo_height method of the widget). That will tell you
> how many visible lines there are.

oh, I see now you had that idea first :) So if my snippet is of any use
for the OP, the credit goes to you!

Best regards

Michael


> 
> 
> On Tue, Feb 13, 2018 at 4:36 PM, Bob van der Poel 
> wrote:
> 
> > I know how to find the number of items. Just like you show.
> >
> > No, this is not the size of the box. I have maybe 2000 entries. I can
> > set the current selection, etc with code like this:
> >
> >   self.lb.select_clear(ACTIVE)   # needed to un-hilite existing
> > selection self.lb.activate(x) # make new item
> > active self.lb.see(x-10)   # force display from 10
> > previous lines
> >   self.lb.select_set(x) # and select the new item
> >
> > If the listbox is 20 lines high, this works perfectly. But, if it is a
> > different size, it doesn't center. In my case I don't know the size
> > of box, so the "-10" is a not-to-intelligent guess.
> >
> > Thanks.
> >
> >
> >
> > On Tue, Feb 13, 2018 at 2:49 PM, Bhaskar Chaudhary
> >  wrote:
> >
> >> Hi Bob
> >>
> >> Are you looking for the number of items in the listbox ?
> >> If yes this should give you the number of items.
> >>
> >> print(len(listbox.get(0, END)))
> >>
> >> Given that each item occupies one line in the list box, i think it
> >> the same as giving the height in lines.
> >>
> >> regards
> >> Bhaskar
> >>
> >>
> >> On 2/13/18, Bob van der Poel  wrote:
> >> > Is there a way to get the current height (hopefully in lines) of a
> >> listbox?
> >> > I'd like to center, vertically, the result of a search.
> >> >
> >> > --
> >> >
> >> >  Listen to my FREE CD at http://www.mellowood.ca/music/cedars
> >> >  Bob van der Poel ** Wynndel, British Columbia, CANADA **
> >> > EMAIL: b...@mellowood.ca
> >> > WWW:   http://www.mellowood.ca
> >> >
> >>
> >
> >
> >
> > --
> >
> >  Listen to my FREE CD at http://www.mellowood.ca/music/cedars 
> > Bob van der Poel ** Wynndel, British Columbia, CANADA **
> > EMAIL: b...@mellowood.ca
> > WWW:   http://www.mellowood.ca
> >
> > ___
> > Tkinter-discuss mailing list
> > Tkinter-discuss@python.org
> > https://mail.python.org/mailman/listinfo/tkinter-discuss
> >
> >



.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Humans do claim a great deal for that particular emotion (love).
-- Spock, "The Lights of Zetar", stardate 5725.6
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Listbox size

2018-02-13 Thread Michael Lange
Hi, 

On Wed, 14 Feb 2018 03:19:29 +0530
Bhaskar Chaudhary  wrote:

> Hi Bob
> 
> Are you looking for the number of items in the listbox ?
> If yes this should give you the number of items.
> 
> print(len(listbox.get(0, END)))
> 
> Given that each item occupies one line in the list box, i think it the
> same as giving the height in lines.

correct, this should work. However, life can be made a tiny bit easier
with

print(listbox.size())

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

War isn't a good life, but it's life.
-- Kirk, "A Private Little War", stardate 4211.8
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Listbox size

2018-02-13 Thread Michael Lange
Hi,

On Tue, 13 Feb 2018 17:09:30 -0600
Bryan Oakley  wrote:

> 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.

huh, did I miss something here? Why not just use size() ?

Best regards

Michael

> 
> 
> 
> On Tue, Feb 13, 2018 at 12:11 PM, Bob van der Poel 
> wrote:
> 
> > Is there a way to get the current height (hopefully in lines) of a
> > listbox? I'd like to center, vertically, the result of a search.
> >
> > --
> >
> >  Listen to my FREE CD at http://www.mellowood.ca/music/cedars 
> > Bob van der Poel ** Wynndel, British Columbia, CANADA **
> > EMAIL: b...@mellowood.ca
> > WWW:   http://www.mellowood.ca
> >
> > ___
> > Tkinter-discuss mailing list
> > Tkinter-discuss@python.org
> > https://mail.python.org/mailman/listinfo/tkinter-discuss
> >
> >



.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

No one wants war.
-- Kirk, "Errand of Mercy", stardate 3201.7
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Listbox size

2018-02-13 Thread Michael Lange
Hi,

On Tue, 13 Feb 2018 15:36:55 -0700
Bob van der Poel  wrote:

> I know how to find the number of items. Just like you show.
> 
> No, this is not the size of the box. I have maybe 2000 entries. I can
> set the current selection, etc with code like this:
> 
>   self.lb.select_clear(ACTIVE)   # needed to un-hilite existing
> selection self.lb.activate(x) # make new item active
>   self.lb.see(x-10)   # force display from 10
> previous lines
>   self.lb.select_set(x) # and select the new item
> 
> If the listbox is 20 lines high, this works perfectly. But, if it is a
> different size, it doesn't center. In my case I don't know the size of
> box, so the "-10" is a not-to-intelligent guess.

you mean, the selected item should be vertically centered in the list?
I believ there is no trivial way to do this, but probably more than one
way with a little tinkering. I set up a simple example with
yview() instead of see(), which seems more appropriate here. I guess this
simple function is certainly not perfect (but maybe it is already good
enough):

##
from Tkinter import *

root=Tk()
l = Listbox(root)
l.pack(side='left', fill='both', expand=1)
s = Scrollbar(root, command=l.yview)
s.pack(side='right', fill='y')
l.configure(yscrollcommand=s.set)

for i in range (2000):
l.insert('end', 'Item %d' % i)

def test(event):
i = 597
wd = event.widget
wd.selection_clear(0, 'end')
wd.selection_set(i)
wd.update_idletasks()
h1 = wd.winfo_height()
i1, i2 = wd.nearest(0), wd.nearest(h1)
wd.yview(i - (i2-i1)/2)

l.bind('', test)
l.focus()

root.mainloop()
#

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

"The combination of a number of things to make existence
worthwhile." "Yes, the philosophy of 'none,' meaning 'all.'"
-- Spock and Lincoln, "The Savage Curtain", stardate
5906.4
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


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

2018-02-02 Thread Michael Lange
Hi,

On Thu, 1 Feb 2018 23:52:34 -0600
alan moore  wrote:

> Thanks.  I managed to work it out.  I think the problem was twofold:
> 
> - I needed to call self.mywidget.focus_force(), because my test root 
> wasn't getting focus
> - I needed to call self.root.update() before *and* after the key events
> 
> This got it working.

Here (debian linux) the test also works if I just change the setUp()
method like this:

def setUp(self):
super().setUp()
self.mywidget = self.create()
self.mywidget.wait_visibility()
self.mywidget.update_idletasks()
self.mywidget.focus_set()

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Is not that the nature of men and women -- that the pleasure is in the
learning of each other?
-- Natira, the High Priestess of Yonada, "For the World is
   Hollow and I Have Touched the Sky", stardate 5476.3.
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Checkbutton and Radiobutton in 3rd state

2017-12-04 Thread Michael Lange
Hi,

On Sat, 2 Dec 2017 21:18:14 +
adil gourinda  wrote:

>In "tkinter.Chechbutton()" and "tkinter.Radiobutton()" widgets if
> the "tristatevalue" option is set to an empty string the indicator
> appears the first time in the 3rd state in which it is gray, but if I
> check the button multiple times I can't put the indicator again in the
> 3rd state, and if I set the "tristatevalue" to other value the
> indicator doesn't appear in the 3rd state
> Thank you for your help

the third state can be accessed if the value of the button's variable is
changed from outside of the widget itself, as in the following example
(please note the difference in the checkbutton's appearance between the
toggle() and toggle2() functions):

###
from Tkinter import *

root=Tk()
v = StringVar(value='2')

cb = Checkbutton(root, text='foobar', variable=v,
onvalue='1', offvalue='0', tristatevalue='2')
cb.pack(padx=100, pady=100)

def toggle(ev):
v.set('2')# tristatevalue -> third state is displayed
cb.bind('', toggle)

def toggle2(ev):
v.set('3')# undefined value -> button appears unchecked
cb.bind('', toggle2)

root.mainloop()
###

Best regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Not one hundred percent efficient, of course ... but nothing ever is.
-- Kirk, "Metamorphosis", stardate 3219.8
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Tkinter option-value

2017-11-23 Thread Michael Lange
On Wed, 22 Nov 2017 22:19:29 -0600
Bryan Oakley  wrote:
 
> 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.

+1   :)

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Genius doesn't work on an assembly line basis.  You can't simply say,
"Today I will be brilliant."
-- Kirk, "The Ultimate Computer", stardate 4731.3
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Cursors

2017-11-11 Thread Michael Lange
Hi,

On Thu, 9 Nov 2017 19:51:16 +
adil gourinda  wrote:

> Where the cursors are stored in the file system ?

in Debian the cursors appear to be in /usr/X11R6/lib/X11/icons ,
probably it's the same with Ubuntu.

> And if I want to make
> my own cursors, to which file's format I should convert the images? I
> work on kubuntu 17.04 LTS

There is a page on the Tcl wiki where this is discussed in detail:

http://wiki.tcl.tk/8674

The exact procedure depends on the platform in use.
On X11 you will have to store the cursor data in an xbm (X-bitmap) file,
then you can do something like:

  root = Tk()
  b = Button(root, text='Close', cursor=('@example.xbm', 'green'),
 command=root.quit)
  b.pack(padx=100, pady=100)
  root.mainloop()

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

But it's real.  And if it's real it can be affected ...  we may not be
able to break it, but, I'll bet you credits to Navy Beans we can put a
dent in it.
-- deSalle, "Catspaw", stardate 3018.2
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Convert Canvas to bitmap image

2017-10-23 Thread Michael Lange
On Mon, 23 Oct 2017 18:53:24 +0200
Michael Lange <klappn...@web.de> wrote:

> you can use the tkImg library to do that. tkImg's "window" image type
> allows you to create "screenshots" of Tk widgets on the fly.

Oh, and I forgot to mention, with the window image type it is necessary
that the canvas is *completely* visible on the screen, otherwise you
might end up with blacked-out image parts or even a TclError. So for a
real big canvas that requires scrolling I am afraid this is no option.

Best regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

War isn't a good life, but it's life.
-- Kirk, "A Private Little War", stardate 4211.8
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Convert Canvas to bitmap image

2017-10-23 Thread Michael Lange
Hi,

On Mon, 23 Oct 2017 12:07:20 +
Vasilis Vlachoudis  wrote:

> Dear all,
> 
> what can be the most efficiency way of converting the canvas to a
> bitmap (what ever type, gif png, jpg...) image? Right now we are saving
> to postscript and then using the PIL library convert it to bitmap.

you can use the tkImg library to do that. tkImg's "window" image type
allows you to create "screenshots" of Tk widgets on the fly.
To load the "window" image type, do:

somewidget.tk.call('package', 'require', 'img::window')

Or to load all available image formats:

somewidget.tk.call('package', 'require', 'Img')

Then you should be able to load the canvas as image and export the
image to a gif or png file (or any other format your tkImg install
supports) with something like:

img = Tkinter.PhotoImage(format='window', data=canvas._w)
img.write('canvas.png', format='png')
del img

tkImg can be a bit tricky though. I have had problem with the window
image type when using Tkinter's default widget names. From my experience
it seems a good idea to create the widget in question and all its
ancestors with the widget name explicitely set, as in

   f0 = Frame(parent, name='f0')

Loading all image types at once also often causes problems (resp.
crashes), so I recommend to explicitely only load the image types you
really need.

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

When a child is taught ... its programmed with simple instructions --
and at some point, if its mind develops properly, it exceeds the sum of
what it was taught, thinks independently.
-- Dr. Richard Daystrom, "The Ultimate Computer",
   stardate 4731.3.
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] tcl/tk's syntax to python's syntax

2017-10-23 Thread Michael Lange
Hi,

On Sun, 22 Oct 2017 21:11:48 +
adil gourinda  wrote:

> With the aim to make translation of tcl/tk's syntax to python's syntax
> more easy I made this flowchart and I ask you to check it.
> 
> Thanks for your help

I think the translation of the Tk pathName is problematic. One thing that
might come closer could be

".parentWidget.childWidget" -> "Instance"
".parentWidget" -> "parentWidget"

But strictly speaking I think this is not correct either. If the Tk root
window is the parent, parentWidget is only "." . If a Frame ".f" is the
parent, parent widget *is* ".f" in Tk,and a Button widget "b" that is a
child of ".f" in Tk *is* ".f.b". Of course considering this the chart
might look a bit pointless, like

"parentWidget" -> "parentWidget"

Actually the widgets' names (as "b" and "f" in the above example) go to
the widget's "name" option in Python, which is hardly ever used though
(in Tkinter we usually let Python assign the widget names automatically
which leads to something that looks like ".1234567890.1234567891" instead
of ".f.b").

I hope this makes some sense, and maybe one of the Tk experts here can
provide a better explanation.

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

It [being a Vulcan] means to adopt a philosophy, a way of life which is
logical and beneficial.  We cannot disregard that philosophy merely for
personal gain, no matter how important that gain might be.
-- Spock, "Journey to Babel", stardate 3842.4
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Display Files in Directory

2017-09-12 Thread Michael Lange
Hi,

On Tue, 12 Sep 2017 11:35:32 +1200
Greg Ewing  wrote:

> Austin Redding wrote:
> > Is there any fix to allow for the contents of a directory to be 
> > displayed (like 'askopenfilename'), but maintain the functionality of 
> > 'askdirectory'?
> 
> This seems to be platform-dependent. On MacOSX I get a
> dialog that shows the filenames greyed out.
> 
> I'm guessing you're using Windows, where the system
> supplied directory choosing dialog is completely
> different from the one for choosing filenames and
> doesn't show files. If that's the case, there's
> probably nothing you can do about it, because
> tkinter isn't responsible for the difference.

it might be X11 as well, here you still get those Win95-style dialogs
provided by Tk (and since Austin said he checked the source code I
thought he referred to tkfbox.tcl, but of course I might be wrong there).

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

You humans have that emotional need to express gratitude.  "You're
welcome," I believe, is the correct response.
-- Spock, "Bread and Circuses", stardate 4041.2
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Display Files in Directory

2017-09-11 Thread Michael Lange
Hi Austin,

On Mon, 11 Sep 2017 10:44:07 -0500
Austin Redding  wrote:

> I'm attempting to use 'askdirectory' in order to populate a widget with
> the relevant files in the user selected directory.  However, when using
> 'askdirectory' the user isn't able to see the files inside the
> directory, unlike 'askopenfilename' which displays all the files.
> 
> Is there any fix to allow for the contents of a directory to be
> displayed (like 'askopenfilename'), but maintain the functionality of
> 'askdirectory'?  I want to use 'askdirectory' because I don't want the
> user to have to create a new file dialog window every time they want to
> switch between files located in the same directory.
> 
> I've dug through the source code, but I can't seem to pinpoint where the
> decision to display/show files is made depending on the choice of
> 'askopenfilename', 'askdirectory', etc.  Any help or direction would be
> greatly appreciated.

I don't think this can be done with the plain Tk file dialog. Maybe you
could use the tix.ExFileSelectBox or the tix.DirTree instead, or set up
something yourself, like checking the contents of the directory returned
by askdirectory() and insert the file names into a listbox.

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Compassion -- that's the one things no machine ever had.  Maybe it's
the one thing that keeps men ahead of them.
-- McCoy, "The Ultimate Computer", stardate 4731.3
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Drag n drop from another application

2017-08-25 Thread Michael Lange
Hi Vasilis,

On Fri, 25 Aug 2017 14:29:34 +
Vasilis Vlachoudis  wrote:

> Great thanks.
> I will give it a try.

I finally uploaded the new version 0.3 of TkinterDnD2, this version now
works with both Python2 and Python3. I also added a few new (hopefully
helpful) demo scripts. I think I had to change the API to fix some bugs
(although at the moment I cannot remember the details :) , so if you
already downloaded v. 0.1 you are probably better off replacing it. I did
a brief test with the demos here, as far as I can see everything seems to
work ok. If you still find a bug, please report it here, then I will try
to fix it asap.

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

No one may kill a man.  Not for any purpose.  It cannot be condoned.
-- Kirk, "Spock's Brain", stardate 5431.6
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Drag n drop from another application

2017-08-25 Thread Michael Lange
Hi Vasilis,

On Fri, 25 Aug 2017 08:21:03 +
Vasilis Vlachoudis  wrote:

> Thank you Michael,
> 
> is this the same with the Tkdnd.py module inside tkinter, or it is an
> extension of it?

no, Tkdnd.py is pure Tkinter code and can only handle dnd within one
Tkinter program.
For "real" dnd you will need tkdnd. BTW, iirc there is a problem with
tkdnd-2.6 (which is still the version included with debian and probably
other linux/unix systems). I am not 100% sure, but I believe drops would
only work if the drop target is a direct child of the toplevel window,
which has been fixed with tkdnd-2.8. I never really used tkdnd in a real
application, so it's a little hard to remember exactly, it was something
like this. With tkdnd-2.8 also dragging from Tkinter to the file manager
should work, so if you want to use it, it might be a good idea to
upgrade (although a number of X11 file managers I tested behaved
differently, some accepted the drops from Tk, others wouldn't and pcmanfm
always crashed :)
You can find the latest version at
https://sourceforge.net/projects/tkdnd/files/ ,
compiling should be rather easy, here a simple ./configure && make &&
make install did the job.

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Most legends have their basis in facts.
-- Kirk, "And The Children Shall Lead", stardate 5029.5
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Problem on Notebook Widget

2017-08-05 Thread Michael Lange
Hi Emmanuel,

On Tue, 1 Aug 2017 10:36:08 +0100
Emmanuel Adeiza  wrote:

> i am currently working on a project(using tkinter) that uses the
> Notebook widget and has an area that serves as an editor but when i
> click on 'new file' it does open it in a new tab but does not show the
> tab, the previous tab that i was on before clicking 'new file' is still
> the one on display... i need it to automatically display the new tab
> instead of me having to click on it before i see the tab
> this is the source code for that:
> def new(self,filename1='Untitled'):
> global content_text
> filename=filename1
> tab_frame=Frame(myNote,height=600, width=1350,
> background='#113147208', borderwidth=1, relief= FLAT)
> line_number_bar = Text(tab_frame, width=2, padx=2,
> takefocus=True,border=0, background='tan', state='disabled',
> wrap='none', cursor = 'dotbox')
> line_number_bar.pack(side='left', fill='y')
> content_text = Text(tab_frame, wrap='word',
> background='AntiqueWhite3')
> content_text.pack(expand='yes', fill='both')
> scroll_bar = Scrollbar(content_text, cursor = 'dotbox')
> content_text.configure(yscrollcommand=scroll_bar.set)
> scroll_bar.config(command=content_text.yview)
> scroll_bar.pack(side='right', fill='y')

you need to explicitely add the newly created Frame as a new "slave" to
the Notebook, then you can tell the Notebook to select the newly created
tab, like this:

myNote.add(tab_frame, text=filename1)
myNote.select(myNote.index('end')-1) # or: myNote.select(
 #tab_frame)

Hre you can find a complete reference of the Notebook widget (and other
Tkinter widgets as well :)

http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-Notebook.html

I hope this helps!

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

I'm a soldier, not a diplomat.  I can only tell the truth.
-- Kirk, "Errand of Mercy", stardate 3198.9
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] tkinter issue while using matplotlib module..

2017-07-21 Thread Michael Lange
Hi,

On Mon, 17 Jul 2017 15:02:04 +0530
niraj pandey  wrote:

> Hi ,
> 
> I am getting the error while running one of my python script.
> 
> import matplotlib.pyplot as plt
> plt.plot([1,2,3,4])
> plt.ylabel('some numbers')
> plt.show()

I don't know about matplotlib, but this code snippet works here.

> Error:
> 
> raceback (most recent call last):
>   File "test.py", line 4, in 
> plt.show()
>   File
> "/grid/common/pkgs/python/v2.7.2/lib/python2.7/site-packages/matplotlib/pyplot.py",
> line 253, in show
> return _show(*args, **kw)
>   File
> "/grid/common/pkgs/python/v2.7.2/lib/python2.7/site-packages/matplotlib/backend_bases.py",
> line 163, in __call__
> manager.show()
>   File
> "/grid/common/pkgs/python/v2.7.2/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py",
> line 610, in show
> self.canvas.manager.window.attributes('-topmost', 1)
>   File
> "/grid/common/pkgs/python/v2.7.2/lib/python2.7/lib-tk/Tkinter.py", line
> 1493, in wm_attributes return self.tk.call(args)
> _tkinter.TclError: wrong # args: should be "wm attributes window"

This looks strange, since the call to attributes() seems to be fine.
I can only guess here. You are apparently using a custom python version,
how do you start the program? Is it possible that somehow the system
default python install conflicts with your custom python here? (Not sure
if this could cause an error like this at all, though.)

Maybe for a test you could try to comment out line 610 in
backend_tkagg.py and see what happens then?

Regards

Michael



.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

If some day we are defeated, well, war has its fortunes, good and bad.
-- Commander Kor, "Errand of Mercy", stardate 3201.7
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Dragging and dropping into a database

2017-05-01 Thread Michael Lange
Hi,

On Mon, 1 May 2017 11:12:43 -0600
Bob Greschke  wrote:

> We have a Python/Tkinter inventory program that I wrote that users
> access using X-Windows (Xming, XQuartz, etc.). It can't directly access
> files on the users computer, of course, but cutting and pasting text
> into a Toplevel with a text widget in it does make that text available
> to the program. You can hit a Save button, the program will read the
> Text() and save it to the database, for example.
> 
> Could the same thing be done with a .gif or a .pdf file? If there was a
> Toplevel that was designed for dragging and dropping .gif/.png files
> to, could it "interpret" the dragged stuff in such a way that it could
> then take the info and turn it into let's say uuencode, display that in
> the window, then when the user hits a Save button that uuencoded text
> gets read, run through PhotoImage and saved in the database?
> 
> Actually, it might be nice to be able to do the same thing with a .csv
> file. Yearly we have to look for differences between a spreadsheet that
> "they" keep and what is in the inventory database. It's a manual labor
> thing. If the user could just drop the .csv into a window and run the
> comparison function on the resulting text that would be nicer than copy
> and paste. Right now the .csv has to be put in a specific place on the
> server (like by me) and then the comparison function executed. Adding
> pictures of items in the inventory is handled the same way. If I could
> access files on the remote (to the server) machines that would solve a
> bunch of things.
> 
> Dragging and dropping a file from 'outside' of a Toplevel would
> actually be like accessing the file on the users machine, wouldn't it?
> That doesn't sound good. Could the user copy and paste the file into
> the Toplevel?
> 
> I haven't even looked into dragging and dropping yet. That might be
> beyond my brain cell count as it is.

for drag and drop you might try the tkdnd wrapper from
http://tkinterdnd.sourceforge.net/
(it's pretty old Python2-code; from a quick glance I think that changing
the import line from
import Tkinter
into something like
try:
import Tkinter
except ImportError:
import tkinter as Tkinter
might be all that is needed to make it work with Python3 though)
With the tkdnd test script I can drop a bunch of filenames from Xfe onto a
Tk window here (Debian Jessie). However I am not sure if this helps you
any, since of course these files would still have to be read...

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

All your people must learn before you can reach for the stars.
-- Kirk, "The Gamesters of Triskelion", stardate 3259.2
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


  1   2   3   4   >