Invisable tkinter Main window

Post here if you need help with creating a Graphical User Interface in Python.

Invisable tkinter Main window

Postby Larz60+ » Mon May 05, 2014 5:09 pm

Hi again,

Thanks for mainitaining this forum, it's been (and will continue to be) a great python tutor for me.

I have a small class (only one function so far) of dialogs for opening the files and selecting starting directories that I need for my application. I am using the tkinter fieldialog library and python3.3 on fedora 20. The class works exactly as I want it to, except for one thing. I don't know how to make the main TK window invisable, and I don't know how to gracefully destroy it (main window) when when I finish with the dialog window.

Here's the code:

Code: Select all
import tkinter
import tkinter.filedialog
import time;

class fileDialogs():
    def openLog():
        """Opens selected Logfile."""
        ticks = time.time()
        logFileName = ('log' + str( int(ticks) ) + '.log')
        file_opt = options = {}
        options['title'] = 'Open Log File'
        options['initialdir'] = '.'
        options['initialfile'] = (logFileName)
        options['defaultextension'] = '.log'
        options['filetypes'] = [('log files', '.log'),
                                ('all files', '.*'),
                                ('text files', '.txt')]
        return tkinter.filedialog.asksaveasfilename(**file_opt)

logName = ''

logName = fileDialogs.openLog()
print( 'Logname: ', logName )



As soon as I fix these two issues, I'll add other code that I require. I'd appreciate your thoughts on this. I'm thinking there must be some sort of 'not visible' attribute, and a destroy method as well.

Thanks,
Larz
Larz60+
 
Posts: 208
Joined: Thu Apr 03, 2014 4:06 pm

Re: Invisable tkinter Main window

Postby Larz60+ » Tue May 06, 2014 6:54 pm

This must be a dumb question as nobody has replied. The reason why I did not want the main window to show is that the rest of the module is a console program and it's clumsy to have to click the 'x' box on the main window to make it go away after the file dialog has been used. I could still have a main window, but there's nothing to display while the main process is running ( I could throw a progress bar up I suppose). I was hoping for a boolean 'Visible' attribute or something similar that I could set False so that the window wouldn'd display, but I can't find one. I'm really only interested in the dialog window showing.

Larz
Larz60+
 
Posts: 208
Joined: Thu Apr 03, 2014 4:06 pm

Re: Invisable tkinter Main window

Postby metulburr » Tue May 06, 2014 7:18 pm

you would call
Code: Select all
root.withdraw()

where root is your main window.

Code: Select all
import tkinter as tk
root = tk.Tk()
root.withdraw()
root.mainloop()
#root.deiconify()

deiconify to bring it back again.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1471
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Invisable tkinter Main window

Postby Larz60+ » Tue May 06, 2014 7:32 pm

Excellent!

Thanks much!

Larz
Larz60+
 
Posts: 208
Joined: Thu Apr 03, 2014 4:06 pm


Return to GUI

Who is online

Users browsing this forum: Bing [Bot] and 2 guests