jarvisteach / appJar

Simple Tkinter GUIs in Python
http://appJar.info
Other
615 stars 68 forks source link

setLabelSticky() crashes when used with python2 #571

Closed NZJourneyMan closed 4 years ago

NZJourneyMan commented 5 years ago

Bug Report


Context


I'm trying to port a small script I wrote in python3 to python2 and I'm running into issues with .setLabelSticky()

Expected Behaviour


.setLabelSticky() should not cause the app to crash

Actual Behaviour


Python3 works fine, python2 crashes

Any error messages produced by appJar


$ ./test.py
2019-03-12 22:27:09,893 appJar:ERROR [Line 10->1706/__exit__]: ContextManager failed: coercing to Unicode: need string or buffer, _tkinter.Tcl_Obj found
Traceback (most recent call last):
  File "./test.py", line 10, in <module>
    app.setLabelSticky('status', 'nsew')
  File "<string>", line 1, in setLabelSticky
  File "/data/home/mark/Development/SailingResults/appJar/appjar.py", line 3036, in configureWidget
    self._repackWidget(item, info)
  File "/data/home/mark/Development/SailingResults/appJar/appjar.py", line 3602, in _repackWidget
    ginfo = widget.grid_info()
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 2000, in grid_info
    self.tk.call('grid', 'info', self._w))
TypeError: coercing to Unicode: need string or buffer, _tkinter.Tcl_Obj found

Sample code, demonstrating the issue


$ cat test.py 
#!/usr/bin/env python2

from appJar import gui

with gui('Test') as app:
    app.setSize(250, 200)
    with app.labelFrame('Status'):
        app.addLabel('status', 'Unknown')
        app.setLabelBg('status', 'grey')
        app.setLabelSticky('status', 'nsew')

What steps are needed to reproduce the bug


Run the code

Version Information


$ python2 ./test.py -v
appJar: 0.93.0 Python: 2.7.6 TCL: 8.6, TK: 8.6 Platform: Linux pid: 10410
locale: en_GB
jarvisteach commented 5 years ago

Have done a quick test on my computer - can't reproduce this error.

A quick Google, turns up this: https://mail.python.org/pipermail/tkinter-discuss/2013-December/003538.html from 2013.

It's an issue with the version of tkinter being used by your python 2 installation - which I notice is a newer version than mine...

According to the above link, we can try to build in catching this type of issue, and then converting the object to string manually - not something that I think we should do.

Or, you can try turning off TclObjects

Apparently, adding the following code, before importing appJar, might help:

import Tkinter
Tkinter.wantobjects = False

It certainly didn't break anything on mine...

NZJourneyMan commented 5 years ago

That worked, thanks!

According to the above link, we can try to build in catching this type of issue, and then converting the object to string manually - not something that I think we should do.

Perhaps consider adding Tkinter.wantobjects = False in the init part of the library when you decide to load Tkinter instead of tkinter?

jarvisteach commented 5 years ago

It's not a bad idea, I just worry about breaking it for someone else...

Maybe it could be a flag, so people can opt to enable it, if they're having issues - I could look to catch that kind of error and report how to avoid it...

NZJourneyMan commented 5 years ago

True, some may be manipulating the Tkinter objects directly, so it would make sense to not change the default behaviour. If you could make an override argument in the constructor that would work nicely.

I like the idea of catching the exception and giving a useful message. Unheard of!

Mark Wilson

On Sat, 16 Mar 2019 at 08:34, Richard Jarvis notifications@github.com wrote:

It's not a bad idea, I just worry about breaking it for someone else...

Maybe it could be a flag, so people can opt to enable it, if they're having issues - I could look to catch that kind of error and report how to avoid it...

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jarvisteach/appJar/issues/571#issuecomment-473511796, or mute the thread https://github.com/notifications/unsubscribe-auth/AA_oKqYfRZidO3sf1un-sJCGnbByd2ATks5vXKysgaJpZM4bsCkL .