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


Messages In This Thread
Tkinter GUI works on Windows but not on Ubuntu - by danbei - Jun-21-2017, 08:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter two windows instead of one jacksfrustration 7 778 Feb-08-2024, 06:18 PM
Last Post: deanhystad
  pass a variable between tkinter and toplevel windows janeik 10 2,140 Jan-24-2024, 06:44 AM
Last Post: Liliana
  Tkinter multiple windows in the same window tomro91 1 788 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  Dual Tkinter windows and shells Astrikor 6 3,835 Sep-03-2020, 10:09 PM
Last Post: Astrikor
  Tkinter scaling windows conten to or with its size not working Detzi 5 4,361 Jan-12-2020, 12:42 PM
Last Post: Detzi
  How to close one of the windows in Tkinter scratchmyhead 3 4,760 Dec-21-2019, 06:48 PM
Last Post: pashaliski
  Using tkinter on Windows to launch python 3 scripts Mocap 1 2,686 Jul-17-2019, 05:16 AM
Last Post: Yoriz
  [Tkinter] Using tkinter and mutiprocess ok on windows, locks up on ubuntu? ice 3 2,617 May-29-2019, 08:44 AM
Last Post: ice
  Int Variables in different Tkinter windows only returning 0 harry76 3 4,082 May-26-2019, 10:24 AM
Last Post: Yoriz
  [Tkinter] Ignore windows scaling in tkinter Gangwick 2 4,420 Jul-23-2018, 02:41 PM
Last Post: Gangwick

Forum Jump:

User Panel Messages

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