Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Python Institute Exam PCPP-32-101 Topic 4 Question 43 Discussion

Actual exam question for Python Institute's PCPP-32-101 exam
Question #: 43
Topic #: 4
[All PCPP-32-101 Questions]

If w is a correctly created main application window, which method would you use to foe both of the main window's dimensions?

Show Suggested Answer Hide Answer
Suggested Answer: C

1. w.resizable()

Theresizable()method takes two Boolean arguments,widthandheight, that specify whether the main window can be resized in the corresponding directions. PassingFalseto both arguments makes the main window non-resizable, whereas passingTrueto both arguments (or omitting them) makes the window resizable.

Here is an example that sets the dimensions of the main window to 500x400 pixels and makes it non-resizable:

import tkinter as tk

root = tk.Tk()

root.geometry('500x400')

root.resizable(False, False)

root.mainloop()


Tkinter documentation:https://docs.python.org/3/library/tk.html

Tkinter tutorial:https://www.python-course.eu/python_tkinter.php

The resizable () method of a tkinter window object allows you to specify whether the window can be resized by the user in the horizontal and vertical directions. You can pass two boolean arguments to this method, such as w.resizable (False, False), to prevent both dimensions from being changed.Alternatively, you can pass 0 or 1 as arguments, such as w.resizable (0, 0), to achieve the same effect1.

1: https://stackoverflow.com/questions/36575890/how-to-set-a-tkinter-window-to-a-constant-size

Other methods that can be used to control the window size are:

w.geometry () : This method allows you to set the initial size and position of the window by passing a string argument in the format ''widthxheight+x+y'', such as w.geometry (''500x500+100+100'')12.

w.minsize () and w.maxsize (): These methods allow you to set the minimum and maximum size of the window in pixels, such as w.minsize (500, 500) and w.maxsize (1000, 1000)12.

w.pack_propagate () and w.grid_propagate (): These methods allow you to enable or disable the propagation of the size of the widgets inside the window to the window itself. By default, these methods are set to True, which means that the window will adjust its size according to the widgets it contains. You can set these methods to False or 0 to prevent this behavior, such as w.pack_propagate (0) or w.grid_propagate (0).

w.place (): This method allows you to place the window at a specific position and size relative to its parent window or screen. You can use keyword arguments such as x, y, width, height, relx, rely, relwidth, and relheight to specify the coordinates and dimensions of the window in absolute or relative terms, such as w.place (x=0, y=0, relwidth=1, relheight=1).

2: https://stackoverflow.com/questions/25690423/set-window-dimensions-in-tkinter-python-3 : https://stackoverflow.com/questions/36575890/how-to-set-a-tkinter-window-to-a-constant-size/36576068#36576068 : https://www.skotechlearn.com/2020/06/tkinter-window-position-size-center-screen-in-python.html

Contribute your Thoughts:

Roselle
3 days ago
I disagree, I believe the correct method is B) w.fixdim()
upvoted 0 times
...
Doyle
7 days ago
I think the correct method is A) w.fixshape()
upvoted 0 times
...
Buddy
14 days ago
I think B) w.fixdim() is the correct answer. It's the most straightforward way to set both the width and height of the main window.
upvoted 0 times
Reta
3 days ago
I agree, B) w.fixdim() is the way to go.
upvoted 0 times
...
...

Save Cancel