A newbie question about using tix

David Sumbler david at aeolia.co.uk
Tue Apr 30 11:40:43 EDT 2019

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

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?


More information about the Python-list mailing list