Stewart Baskin | 29 Apr 16:31 2016

Tkinter multiple font sizes in same text input

Hello,

 

Thank you in advance for your assistance with this query. I would like to produce multiple font sizes on the same line. For example:

 

## mg/l

 

I know how to assign the font type/size, but am unable to do this twice (only the second text and font size appear in the window).

 

Is it possible to assign multiple font sizes to the same line in Tkinter?

 

Thank you,

Stew

_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss <at> python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss
Mickey Kocic | 21 Apr 16:59 2016
Picon

Re: standard tkinter command set

Could you provide me with a link to the list of the standard tkinter/tcl command set? I had to put up with the snarkoids at Stack Overflow before one (unintentionally!) informed me that the Text widget has its own native bindings for cut, copy and paste, and that i had wasted time wrapping them in my application. Before I go through that again I'd like to be properly informed about the features.

Thanks for all replies.

Mickey
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss <at> python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss
Stefan Richthofer | 5 Apr 19:31 2016
Picon
Picon

Help/advice needed for Tkinter related JyNI issue

Hello everybody,

I am the author of the JyNI-project (www.jyni.org) which aims to support native CPython extensions in Jython.
Some basic Tkinter stuff is known to work with JyNI on Linux, but unfortunately hangs on OSX:
https://github.com/Stewori/JyNI/issues/4
In this thread we collected everything we know about this issue so far.
The issue is rather strange in the sense that the sample works well on Linux, while it hangs on OSX. Briefly
speaking, on OSX TCL/TK does not produce a particular event the loop is waiting for and does not display the
window. However logging suggests that calls to TCL/TK API are identical between Linux and OSX runs, so we
are really stuck here in finding out what is different on Linux (our current logging does not cover
function argument values though).
I think there must be something subtle JyNI is doing wrong and that only manifests on OSX. (Running with
CPython the sample succeeds on that system.)
Any advise how I can find the reason for the missing event would be helpful. My usual divide and conquer
debugging approach struggles here because I don't know enough about TCL/TK to trace the cause for the
issue through its API. Is there something like an internal log of TCL accessible? Or a way to see the events
processed by TCL_DoOneEvent?

Thanks in advance for any helpful hint.

Stefan
Bob Greschke | 11 Feb 00:30 2016

Transferring tags from one Text() to another

I write stuff to a Text() and some words and lines are different colors or are links (binds) using Tags. I can
Text().get(0.0, END), get all of the text, then insert that in another Text() to make a copy, but how do I
get/transfer the other "formatting" info? The binds aren't real important, but the different colored
text would be nice.

Thanks!

Bob
Reinis Danne | 5 Feb 20:44 2016
Picon

Debugging non-zero exit code

Hi!

I'm trying to debug why BKChem prints '0' and exits with exit
code 1. As far as I can tell that is not directly in the app.
I tried to debug it with gdb, but it tried (and failed) to start
the app again after I have pressed the close button, so I didn't
get any useful info out of it. How could I debug this issue?

The application setup code is in bkchem.py and the main class is
in main.py. To test:
$ git clone https://gitlab.com/bkchem/bkchem.git
$ cd bkchem
$ git submodule init
$ git submodule update
$ python bkchem/bkchem.py

Should work with Python 2 and 3.

Any tips how to deal with this would be appreciated. Also it
would be great if someone could review the tkinter setup sequence.

Reinis
Reinis Danne | 4 Feb 13:58 2016
Picon

Moving object on page leaves afterimage on Python 3 but not on 2

Hi!

I'm porting a chemistry drawing program BKChem [1] to Python 3
using the shared codebase between versions 2 and 3. It is working
fine on Python 2, but if I run it with Python 3 I have an issue
with redrawing the page.

The issue is that if I move an object by mouse then it leaves an
image of the object in the old place while moving the object to
the new place (Python 3). There is no such afterimage with Python
2. Similar effect can be achieved if object is deleted or its
creation is undoed - object is removed, but lines remain. It
seems that text is updated correctly, only bonds (lines) have the
issue.

Any ideas where the bug might be and how to debug it? As far as I
understand the moving of the object and updating the drawing is
up to tkinter or the underlying tk. It could be an issue with the
app losing track of the object, but in that case it wouldn't
create new lines (if I drag and drop an object several times,
several afterimages remain, but not 100% of the time; usually the
very first move works, but later ones produce the afterimages).
So I think it is a lower level issue.

To test:
$ git clone https://gitlab.com/bkchem/bkchem.git
$ cd bkchem
$ git submodule init
$ git submodule update
$ python3 bkchem/bkchem.py

Regards,
Reinis

[1] https://gitlab.com/bkchem/bkchem
ingo | 23 Jan 10:05 2016
Picon

'connect' widget classes in an application

In the code below I get the error below.
I'm trying to create a class for several widgets and make the "interact" 
within a main Frame. Can't figure it out (lack of programming 
experience) and couldn't find an eye opening example.

I understand that the toolbar has no way to access the txt in the 
editor, how do I make it so?

TIA,

Ingo

ERROR:

Exception in Tkinter callback
Traceback (most recent call last):
   File "\Python35-32\lib\tkinter\__init__.py", line 1549, in __call__
     return self.func(*args)
   File "twoclass.py", line 10, in <lambda>
     command=lambda: self.txt.insert(END, 'Button pressed.\n')
AttributeError: 'Ttoolbar' object has no attribute 'txt'

CODE:

from tkinter import *

class Ttoolbar(Frame):

     def __init__(self, parent=None):
         Frame.__init__(self, parent)
         self.btn = Button(
             self,
             text='Button',
             command=lambda: self.txt.insert(END, 'Button pressed.\n')
         )
         self.btn.pack(side=LEFT)
         self.pack(side=LEFT)

class Eedit(Text):

     def __init__(self, parent=None):
         txt = Text.__init__(self, parent)
         self.pack(fill='both', expand=Y)

class Aapp(Frame):

     def __init__(self, parent=None):
         Frame.__init__(self, parent)
         self.pack()
         self.makeWidgets()

     def makeWidgets(self):
         tb = Ttoolbar().pack(side=TOP, fill=X)
         ed = Eedit().pack()

if __name__ == '__main__':
     Aapp().mainloop()
ingo | 19 Jan 15:56 2016
Picon

Lost images on tabs ttk.notebook

I'm trying to create a simple tabbed editor and merged two examples 
found on the web. One of those is the one with the closing images on the 
tabs. In the proces of understanding I somehowe lost the images on the 
tabs but not the fuctionality of clicking on the right position of the tabs.

What is going wrong?

TIA, Ingo

import os
from tkinter import *
from tkinter import ttk

class OPMLnotebook(Frame):

     def __init__(self):
         Frame.__init__(self)
         self.master.title('OPML Notebook')
         self._create_panel()

     def _tabbtn_press(self, event):
         x, y, widget = event.x, event.y, event.widget
         elem = widget.identify(x, y)
         index = widget.index(" <at> %d,%d" % (x, y))
         if "close" in elem:
             widget.state(['pressed'])
             widget.pressed_index = index

     def _tabbtn_release(self, event):
         x, y, widget = event.x, event.y, event.widget
         if not widget.instate(['pressed']):
             return
         elem =  widget.identify(x, y)
         index = widget.index(" <at> %d,%d" % (x, y))
         if "close" in elem and widget.pressed_index == index:
             widget.forget(index)
             widget.event_generate("<<NotebookClosedTab>>")
         widget.state(["!pressed"])
         widget.pressed_index = None

     def _create_panel(self):

         imgdir = os.path.join(os.path.dirname(__file__), 'img')
         i1 = PhotoImage("img_close", file=os.path.join(imgdir, 
'close.gif'))
         i2 = PhotoImage("img_closeactive", file=os.path.join(imgdir, 
'close_active.gif'))
         i3 = PhotoImage("img_closepressed", file=os.path.join(imgdir, 
'close_pressed.gif'))

         style = ttk.Style()
         style.element_create("close", "image", "img_close",
             ("active", "pressed", "!disabled", "img_closepressed"),
             ("active", "!disabled", "img_closeactive"), border=10, 
sticky='')
         style.layout("ButtonNotebook", [("ButtonNotebook.client", 
{"sticky": "nswe"})])
         style.layout("ButtonNotebook.Tab", [
             ("ButtonNotebook.tab", {"sticky": "nswe", "children":
                 [("ButtonNotebook.padding", {"side": "top", "sticky": 
"nswe",
                                              "children":
                     [("ButtonNotebook.label", {"side": "left", 
"sticky": ''}),
                     ("ButtonNotebook.close", {"side": "left", "sticky": 
''})]
                 })]
             })]
         )

         self.bind_class("TNotebook", "<ButtonPress-1>", 
self._tabbtn_press, True)
         self.bind_class("TNotebook", "<ButtonRelease-1>", 
self._tabbtn_release)

         nb = ttk.Notebook(width=400, height=400, style="ButtonNotebook")
         nb.pressed_index = None
         nb.enable_traversal()
         nb.pack(fill='both', expand=1)
         self._create_text_tab(nb)
         self._create_text_tab(nb)

     def _create_text_tab(self, nb):
         frame = Frame(nb)
         txt = Text(frame, wrap=WORD, width=40, height=10)
         vscroll = Scrollbar(frame, orient=VERTICAL, command=txt.yview)
         txt['yscroll'] = vscroll.set
         vscroll.pack(side=RIGHT, fill=Y)
         txt.pack(fill='both', expand=Y)
         nb.add(frame, text='Text Editor', underline=0)

if __name__ == '__main__':
     OPMLnotebook().mainloop()
Kevin Walzer | 26 Dec 03:19 2015

Accelerator keys cross-platform

I'm porting a Tkinter application from Mac to Windows and I need a 
cross-platform way to implement accelerator keys for menu entries. In 
Tcl, this is very simple:

  -accelerator "$Command-C"

where $Command can be set to "Command" or "Control" depending on the 
platform.

Python does not have as flexible a string substitution as Tcl, so I'm 
looking for a Pythonic way to do this. Most examples I've seen load 
entirely separate menus depending on the platform, and I'd rather avoid 
duplicating code that way.  Any suggestions or examples that anyone can 
share?

--

-- 
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com
Jeff Hultquist | 22 Dec 18:04 2015

winfo_id on OS/X

I am trying to use tkinter with the Panda3D  (panda3d.org)  graphics library.  I want to position a graphics window into a tkinter frame.  

Attached below is some sample code that uses the frame.winfo_id() as the argument to Panda3D’s setParentWindow method.

This works on Linux and Windows, but seg-faults on OS/X.   It appears the winfo_id is not valid on OS/X.

How can we get a proper handle for the parenting of the 3d view into a tkinter frame?

FWIW, there is a thread is ongoing on the Panda3D forum, but the answer seems to lie deep inside tkinter.

Many thanks.

----------------------------------

from direct.showbase.ShowBase import ShowBase
from panda3d.core import WindowProperties
import Tkinter

base = ShowBase(windowType='none')
base.startTk()

frame = base.tkRoot
frame.update()

id = frame.winfo_id()
width = frame.winfo_width()
height = frame.winfo_height()

props = WindowProperties()
props.setParentWindow(id)
props.setOrigin(0, 0)
props.setSize(width, height)

base.makeDefaultPipe()
base.openDefaultWindow(props=props)   # —— on OS/X, we segfault here

scene = base.loader.loadModel("environment")
scene.reparentTo(base.render)

base.run()

----------------------------------



_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss <at> python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss
Alexander Uvizhev | 28 Nov 22:28 2015
Picon

Tkinter on OS X generates excessive event on non-US input sequence

Hi,
I've found that Tkinter on Mac OS X somehow incorrectly works with events when bound sequence hit on non-US
keyboard layout.
I use Russian keyboard layout along with English and I'm trying now to arrange Undo/Redo shortcuts to work
correctly independent of layout. Under Linux everything works fine from the box. Under OS X it seems like a
bug and when I hit <Command-Cyrillic_ya> which is the same physical keys as <Command-z> tkinter sends
excessive KeyPress event.
Here is the test code.
================
from tkinter import *

class TkExample(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.pack()
        text = Text(self)
        text.pack()
        text.bind('<KeyPress>', self.on_kp)
        text.bind('<<Undo>>', self.on_undo)

    def on_kp(self, event):
        print('CHAR:', event.char)

    def on_undo(self, event):
        print('UNDO')

if __name__ == '__main__':
    root = Tk()
    TkExample(root)
    root.mainloop()
================

When I run the app and hit <Command-z> I get this output:
CHAR:
UNDO

But if I hit <Command-Cyrillic_ya> I see this:
CHAR:  
CHAR: z
UNDO

Under Linux in both cases I get the same output (1).

Can anyone explain this? Maybe this is not a bug?

--

-- 
Alexander Uvizhev
uvizhe <at> yandex.ru

Gmane