473,513 Members | 4,753 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can the window size of tfFileDialog be changed?

2 New Member
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 8471
bvdet
2,851 Recognized Expert Moderator Specialist
The documentation I have provides no way to size the tkFileDialog.askopenfilename dialog box.
Feb 18 '11 #2
JurVogelzang
2 New Member
Thanks. I haven't found anything either, but I hoped someone has figured out a trick.
Feb 18 '11 #3
madpentiste
2 New Member
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
madpentiste
2 New Member
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 New Member
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
12772
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
9651
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
9486
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
9301
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
2279
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
32064
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
1070
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
5148
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
2170
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
2420
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
7373
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
7432
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
5677
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,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.