473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Can the window size of tfFileDialog be changed?

The tkFileDialog module is a handy tool for opening and saving files in Python GUI's with TkInter. However, the pop-up window generated by, e.g., tkFileDialog.askopenfilename is rather small (though it can be resized manually). Is there a possibility to resize it automatically?
Feb 18 '11 #1
5 8441
bvdet
2,851 Expert Mod 2GB
The documentation I have provides no way to size the tkFileDialog.askopenfilename dialog box.
Feb 18 '11 #2
Thanks. I haven't found anything either, but I hoped someone has figured out a trick.
Feb 18 '11 #3
Yes there is a trick. Complicated, because in fact this very function of tkinter uses the system "Open" window capability, instead of creating a whole dialog window with tkinter widgets.

So you have to :
- find which instruction of your operating system resizes windows (mine ins Linux, so it is "wmctrl -r <window title> -e 0,0,0,<width>,<height>"
- use the os.system() function to pass this instruction from python to the OS
- use the multi-threading capabilities of Python, so that once the window exist, which means that the program is hanging because it waits for your answer, you can resize it through another thread that runs while the main thread is hanging.

I shall return to this site with an example later on.
Jun 14 '15 #4
Here is a code example:


Expand|Select|Wrap|Line Numbers
  1. # http://bytes.com/topic/python/answers/908537-can-window-size-tffiledialog-changed
  2. # Code written by madpentiste
  3. #
  4.  
  5. '''
  6. The code herein creates a tkinter dialog "askopenfilename" with window resizing (not supported by default) via linux called from within python
  7.  
  8. It is an adaptation of two recipes (need to scroll down to find the proper code):
  9.  
  10.     http://stackoverflow.com/questions/19790570/python-global-variable-with-thread
  11.  
  12.     http://stackoverflow.com/questions/15528939/python-3-timed-input
  13.  
  14. '''
  15.  
  16.  
  17. from tkinter import *
  18. from threading import Thread
  19. import os, time
  20.  
  21. # Below : instructions that will resize the window, which must be inside a function in order to be called by the threading.Thread() function
  22.  
  23. def resize (windowTitle):
  24.     print('starting resize')
  25.     waitingtime = 0.05
  26.     time.sleep(waitingtime) # waitingtime must be such that the window to be resized exists before the instruction below is executed
  27.     os.system("wmctrl -r " + windowTitle + " -e 0,0,0,1600,900")  # system instruction to resize window named "Title" at width 1600 and height 900
  28.     print('resize done')
  29.  
  30. # Below : instructions that will create the window (to be resized), also inside a function to be called by threading.Thread()
  31.  
  32. def ask_openfilename(windowTitle):
  33.     global filename
  34.     Racine=Tk()
  35.     w = Frame(Racine)
  36.     Racine.withdraw()
  37.     file=w.tk.call('tk_getOpenFile', '-title', windowTitle) # Can add more arguments here see list at https://www.tcl.tk/man/tcl8.4/TkCmd/getOpenFile.htm
  38.                                                             # but beware of the python syntax for w.tk.call, which is << , '-dash_and_argument_name_in_quotes' , argument_value >>.
  39.                                                             # Must add arguments values to the function definition and the tuple of args in << thread_filename = ... >>
  40.  
  41.     filename=str(file)
  42.     return filename
  43.     w.destroy()
  44.     mainloop()
  45.  
  46.  
  47. windowTitle = 'Whichever title for the askopenfilename window'
  48. thread_filename = Thread(target = ask_openfilename, args=(windowTitle,))
  49. thread_resize = Thread(target = resize, args=(windowTitle,))
  50. thread_filename.start()
  51. thread_resize.start()
  52. thread_filename.join()
  53. thread_resize.join()
  54.  
  55. print('Chosen file', filename)
  56.  
  57.  
  58.  
Jun 14 '15 #5
BC79
1
As a follow on to madpentiste's code, I attempted to add the following two lines after line 37 (leaving the rest of the code unchanged):

Expand|Select|Wrap|Line Numbers
  1. w. tk .call('set', '::tk::dialog::file::showHiddenBtn', '1')
  2. w. tk .call('set', '::tk::dialog::file::showHiddenVar', '0')
  3.  
and got the error:

parent namespace doesn't exist

This code has worked in this context before. I'm sure this is a stupid error on my part, but I'm not a Tcl.Tk savant.
Dec 3 '18 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Put 030516 in email subj to get thru | last post by:
I've always been bothered about having to statically declare the size of a Java applet window (container?) in the calling HTML. I've always wanted the moral equivalent of width=50% statement (of...
3
by: spencer | last post by:
Hello, I have an index page with an autoscroller writen with CSS. The problem is the scrolling content(text and inages)'s position is correct but will off position when the broswer(IE) window...
1
by: deko | last post by:
When a user opens my Access database application, I would like the application window to be a certain size (but not maximized). Currently, when my app is first opened, the application window...
7
by: Lauren Quantrell | last post by:
Is there a way in code to freeze the size of the MS Access window or to prevent it from being sized? Thanks. lq
1
by: Kenny | last post by:
The following link will take you to menu of photo galleries. If you open any of the photo galleries you will see that each contains thumbnails. When a thumbnail is clicked, the full-sized version...
7
by: John Fox | last post by:
Dear All, How do I set the size of the window that is showing the database forms? can't find any helps on it. John Fox
0
by: bbqbbq | last post by:
Hi guys, I need a way to automatically adjust the layout of window's content when the window's size get changed. For example, I am creating a web page using ASP.NET. However, when I drag the...
1
by: jobs | last post by:
I have a simple login page with roughly a 300px x 300px image behind the asp.net login control. I need the login control to land in the middle of the image. I want both the image and the login...
1
by: =?Utf-8?B?V29ua28gdGhlIFNhbmU=?= | last post by:
Hello-- Is there a "WPF way" of telling why a Window's size was changed? In other words, is there a way to tell if the dialog was dragged bigger by the user versus a window automatically...
3
by: Annette Block | last post by:
I'm rather new in JavaScript, but I have some experience in php. I learned it's rather easy to open a window of a specified size with JavaScript, that you need to specify the opened file, but I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.