Python Forum

Full Version: Tkinter GUI works on Windows but not on Ubuntu
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I'm coding a GUI with Tkinter that works fine on Windows 8.1 (python 2.7.13, Tkinter 8.5) but not on Ubuntu Mate 17.04 (python 2.7.13, Tkinter 8.6).

Someone else succesfully tested it with python 3.4.2 and 3.5 (Tkinter 8.6) on :
-Ubuntu 16.06 RTS
- Ubuntu 12.04 (netbook)
- Debian 8
and with python 2.7.9 (Tkinter 8.6) on :
-Ubuntu 16.06 RTS
-Debian 8

I creat two listbox and bind them to execute two different functions :
from Tkinter import *

class Interface(Frame):
   def __init__(self, window, **kwargs):
       Frame.__init__(self, window, **kwargs)
       self.grid()

       self.Test1 = Listbox(self,width=5, height=20)
       self.Test2 = Listbox(self,width=5, height=20)

       self.Test1.grid(row=0, column=0, columnspan=1, rowspan=15)
       self.Test2.grid(row=0, column=1, columnspan=1, rowspan=15)

       self.Test1.bind("<<ListboxSelect>>", self.print1)
       self.Test2.bind("<<ListboxSelect>>", self.print2)


       for i in range(10) :
           self.Test1.insert(i, i)
       for i in range(10, 20) :
           self.Test2.insert(i, i)

   def print1(self,event) :
       print self.Test1.get(self.Test1.curselection())
   def print2(self,event) :
       print self.Test2.get(self.Test2.curselection())

if __name__ == '__main__':

   window= Tk()
   window.title('Test')
   window.resizable(width=True, height=True)

   interface = Interface(window)
   window.update_idletasks()
   screen_width = window.winfo_screenwidth()
   screen_height = window.winfo_screenheight()
   w = window.winfo_width()
   h = window.winfo_height()
   window.geometry("%dx%d+%d+%d"%(min(w,screen_width*2/3), min(h,screen_height*2/3), screen_width/2-w/2, screen_height/2-h/2))

   window.mainloop()
When clicking on "3" on the first list and then clicking on "16" on the second list I get :
3
16
Exception in Tkinter callback
Traceback (most recent call last):
 File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1545, in __call__
   return self.func(*args)
 File "test.py", line 27, in print1
   print self.Test1.get(self.Test1.curselection())
 File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 2632, in get
   return self.tk.call(self._w, 'get', first)
TclError: bad listbox index "": must be active, anchor, end, @x,y, or a number
The code seems to execute both binding instructions when the second click occurs.
On Windows and the other configuration listed before everything works as intended: only the correct binding instruction is executed.
Does it works with your configuration ? Have you any idea what could be the problem ?
I'm thinking that this is an EOL (end of line) conversion problem, because you are getting a response
on both platforms, there just on different lines.

I'd put a print statement on the first 20 lines on both platforms.
This will either prove or disprove my theory.
i get this error whenever i switch from one side to the other, regardless of what index im on. On ubuntu 16.04. To me this looks like self.TestX.curselection() returns an empty string instead of an active index of the listbox whenever the other listbox is focused at that time. Or something similar. As seen below i only get the error when i switch to the other column from an already focused and selected index from the other side.

try:
print(size(text1))
print(size(text2))
which should show the number of elements in each Listbox
you can then iterate using:
for n in range(size(text1)):
   print(self.Text1.get(n))
Larz60+ I didn't understand your idea about the end of lines.
Mutulburr, What version of python and Tkinter do you use ?
I also tested with 3 and more listboxes, it appears to bind the current focused listbox and the last focused listbox, I can't figure out why it would do that...
Quote:Larz60+ I didn't understand your idea about the end of lines.
see: http://www.cs.toronto.edu/~krueger/csc20...dings.html

Can cause multi-lines to be programmatically viewed as a single line
Changing end of lines type didn't solve the problem.
Though changing <<ListboxSelect>> by <ButtonRelease-1> in the bind instructions did solve the problem.
It fells less elegant that way, is there any side effect that could occur using ButtonRelease-1 instead of the proper binding event ListboxSelect ?
Take a look at the way I did it here: https://python-forum.io/Thread-Californi...lary-Files
I think it's pretty similar to what you are trying to do.
I didn't see where you used multiple lisbox selection. On my end it apppears that that's the source of the bug, more precisely the <<ListboxSelect>> binding event.
I don't know what's behind it, it's quite opaque for me.
Nevertheless using <ButtonRelease-1> with a few other binding event as <Keyrelease-Up>/<Keyrelease-Down> should do the trick.