A newbie question about using tix

MRAB python at mrabarnett.plus.com
Wed May 1 14:11:07 EDT 2019


On 2019-05-01 17:44, David Sumbler wrote:
 >
 > On Tue, 2019-04-30 at 20:46 +0100, MRAB wrote:
 > > On 2019-04-30 16:40, David Sumbler wrote:
 > > > Running Ubuntu 18.04, Python 3.6.7, tkinter 8.6
 > > >
 > > > I am very new to tkinter.  The simple program I am writing requires
 > > > a
 > > > user file to be selected before it does anything else, so I would
 > > > like
 > > > a file selection dialog in the main window as soon as the program
 > > > launches.
 > > >
 > > > Tkinter only has askopenfilename(), but this produces a popup
 > > > dialog.
 > > > I can get something like what I want by specifying a small Tk()
 > > > window
 > > > and then calling askopenfilename() so that it covers the root
 > > > window.
 > > >
 > > > It's not ideal, though.  From the documentation I thought that the
 > > > tix
 > > > FileSelectBox would do what I wanted, but I just can't get it to
 > > > work.
 > > >
 > > > If I run:
 > > >
 > > >       from tkinter import *
 > > >       from tkinter.tix import FileSelectBox
 > > >       root = Tk()
 > > >       f = FileSelectBox(root)
 > > >
 > > > I get the following:
 > > >
 > > >       Traceback (most recent call last):
 > > >         File "/home/david/bin/Gradient.py", line 4, in <module>
 > > >           f = FileSelectBox(root)
 > > >         File "/usr/lib/python3.6/tkinter/tix.py", line 795, in
 > > > __init__
 > > >           TixWidget.__init__(self, master, 'tixFileSelectBox',
 > > > ['options'], cnf, kw)
 > > >         File "/usr/lib/python3.6/tkinter/tix.py", line 311, in
 > > > __init__
 > > >           self.tk.call(widgetName, self._w, *extra)
 > > >       _tkinter.TclError: invalid command name "tixFileSelectBox"
 > > >
 > > > I realize that assigning the value of FileSelectBox() isn't going
 > > > to
 > > > give me a filename: I'm just trying to get the basic syntax right
 > > > at
 > > > the moment.
 > > >
 > > > I can't figure out what is wrong though.  Have I have misunderstood
 > > > how
 > > > it should be called, or is there something missing from my system?
 > > >
 > >
 > > For some reason, tix widgets don't work with normal tkinter widgets,
 > > so
 > > you can't put a tix FileSelectBox on a tkinter.Tk widget.
 > >
 > > There is, however, a tix.Tk widget that you can use instead:
 > >
 > > import tkinter.tix as tix
 > > root = tix.Tk()
 > > f = tix.FileSelectBox(root)
 > > f.pack()
 >
 > Thanks for that.
 >
 > When I ran the above, I got:
 >
 >      Traceback (most recent call last):
 >        File "/home/david/bin/GradientProfile_v2.py", line 2, in <module>
 >          root = tix.Tk()
 >        File "/usr/lib/python3.6/tkinter/tix.py", line 214, in __init__
 >          self.tk.eval('package require Tix')
 >      _tkinter.TclError: can't find package Tix
 >
 > After an internet search, I tried:
 >
 >     sudo apt install tix-dev tk-dev tk8.6-dev libxft-dev 
libfontconfig1-dev libfreetype6-dev libpng-dev
 >
 > Now when I run the file the program just exits quickly, with no
 > reported errors, but no window(s).  If I add 'root.mainloop()' at the
 > end, I get an empty root window for a fraction of a second, then the
 > program exits with:
 >
 >      Segmentation fault (core dumped)
 >
 > Any suggestions as to where to go from here?
 >
Tested on Raspbian in a terminal window:

sudo apt-get install tix

python3

import tkinter.tix as tix
root = tix.Tk()
f = tix.FileSelectBox(root)
f.pack()

At this point there's a GUi window filled with a file section box.



More information about the Python-list mailing list