I have a Tkinter application that runs as intended, but I'm in the process of 
converting it to Ttk in order to get some of the new widget classes Ttk 
provides. I'm using Python 2.7.5 on a Windows 7 machine. I've run into two 
serious problems doing the conversion that I've been able to find work-arounds 
for, but I'm not sure if the problems are associated with undocumented 
peculiarities with Ttk or if I'm doing something wrong. I describe the 
application and the two problems below. I've worked with Tkinter for several 
months but only recently tried to using Ttk. If anyone knows of a repository 
where issues like these are documented, please let me know.

Thanks

The application frame is a subclass of PanedWindow defined as follows:

      import sys, os
      from Tkinter import *
      import ttk
      from ttk import *

      class App(ttk.PanedWindow):
        ...
        def __init__(self, master, **panedWindowOpts):
                        PanedWindow.__init__(self, master, **panedWindowOpts)

First problem:

I found that the styles I defined for widgets in the application were ignored 
when I made the application's master an instance of Tk() as follows:

      root = Tk()
      app = App(root, style='My.TPanedwindow', orient=VERTICAL)

After considerable trial and error (mostly error) I found that the styles 
worked as advertised, if I changed the application master to an instance of 
Toplevel rather than of Tk:

      top = Toplevel()
      app = App(top, style='My.TPanedwindow', orient=VERTICAL)
top.mainloop()


Second Problem:

When the mainloop executed as above, what appeared to be an extraneous blank 
window was stacked on top of the application window. This window didn't appear 
when I was using basic Tkinter.  I noticed that if I killed the extraneous 
window by clicking on the "X" in the window's upper right corner, it also 
killed the application, which suggested the "extraneous" window was really the 
root window. After searching the documentation and much trial and error, I 
found that I could get the root window to go away without killing my app by 
explicitly calling withdraw() on the root before running the mainloop:

      Tkinter._default_root.withdraw()
      app.mainloop()

This would have been a show stopper if I hadn't been able to work around it, 
because I couldn't give an application to end users that pops up a meaningless 
empty window that they have to close themselves.  I wasn't able to locate much 
documentation on the root window, and I only found out about _default_root by 
looking at Tkinter.py. Further, I found nothing to indicate that the root had a 
withdraw method, and just tried it after running out of all other options I 
could think of. Luckily, it worked.


_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss
  • [Tkinter-discuss] Is... Fleming, Land D. (JSC-ER111)[Jacobs Technology, Inc.]

Reply via email to