Python Forum
[Tkinter] Tkinter GUI works on Windows but not on Ubuntu
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Tkinter GUI works on Windows but not on Ubuntu
#1
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 ?
Reply
#2
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.
Reply
#3
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.

Reply
#4
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))
Reply
#5
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...
Reply
#6
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
Reply
#7
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 ?
Reply
#8
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.
Reply
#9
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Dual Tkinter windows and shells Astrikor 6 1,094 Sep-03-2020, 10:09 PM
Last Post: Astrikor
  Tkinter scaling windows conten to or with its size not working Detzi 5 1,731 Jan-12-2020, 12:42 PM
Last Post: Detzi
  How to close one of the windows in Tkinter scratchmyhead 3 2,219 Dec-21-2019, 06:48 PM
Last Post: pashaliski
  Using tkinter on Windows to launch python 3 scripts Mocap 1 1,096 Jul-17-2019, 05:16 AM
Last Post: Yoriz
  [Tkinter] Using tkinter and mutiprocess ok on windows, locks up on ubuntu? ice 3 1,371 May-29-2019, 08:44 AM
Last Post: ice
  Int Variables in different Tkinter windows only returning 0 harry76 3 2,289 May-26-2019, 10:24 AM
Last Post: Yoriz
  [Tkinter] Ignore windows scaling in tkinter Gangwick 2 2,601 Jul-23-2018, 02:41 PM
Last Post: Gangwick
  Code fails on Mac, works on Windows and Raspberry Pi eugenedakin 4 2,366 May-30-2018, 03:49 AM
Last Post: eugenedakin
  Using a class to create instances of Tkinter Toplevel() windows nortski 2 7,419 Mar-27-2018, 11:44 AM
Last Post: nortski
  Multi windows in tkinter buttons not responding correctly curtjohn86 13 7,207 Jul-01-2017, 03:42 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020