Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent a window from being resized with tkinter?

I have a program which creates a window where a message is displayed according to a check box.

How can I make the window size constant when the message is displayed and the message is not displayed?

from Tkinter import *  class App:     def __init__(self,master):         self.var = IntVar()         frame = Frame(master)         frame.grid()         f2 = Frame(master,width=200,height=100)         f2.grid(row=0,column=1)         button = Checkbutton(frame,text='show',variable=self.var,command=self.fx)         button.grid(row=0,column=0)         msg2="""I feel bound to give them full satisfaction on this point"""         self.v= Message(f2,text=msg2)     def fx(self):         if self.var.get():             self.v.grid(column=1,row=0,sticky=N)         else:             self.v.grid_remove()  top = Tk() app = App(top)             top.mainloop() 
like image 732
mahes Avatar asked Feb 22 '14 18:02

mahes


People also ask

How do I make my Tk window not resizable?

Tkinter initially creates a resizable window for every application. Let us suppose that we want to make a non-resizable window in an application. In this case, we can use resizable(height, width) and pass the value of height=None and width=None.

How do I lock the size of a tkinter window?

The whole window size is frozen by using resizable(width=False, height=False) , or simply resizable(False, False) .

What statement you will write to prevent the user from resizing the window at runtime in Python?

-> To make window non-resizable user can pass 0 or False.

How do I change the default window size in tkinter?

Syntax – geometry() To set a specific size to the window when using Python tkinter, use geometry() function on the Tk() class variable. where width and height should be replaced with integers that represent the width and height of the window respectively.


2 Answers

This code makes a window with the conditions that the user cannot change the dimensions of the Tk() window, and also disables the maximise button.

import tkinter as tk  root = tk.Tk() root.resizable(width=False, height=False) root.mainloop() 

Within the program you can change the window dimensions with @Carpetsmoker's answer, or by doing this:

root.geometry('{}x{}'.format(<widthpixels>, <heightpixels>)) 

It should be fairly easy for you to implement that into your code. :)

like image 192
anon582847382 Avatar answered Sep 28 '22 07:09

anon582847382


You can use the minsize and maxsize to set a minimum & maximum size, for example:

def __init__(self,master):     master.minsize(width=666, height=666)     master.maxsize(width=666, height=666) 

Will give your window a fixed width & height of 666 pixels.

Or, just using minsize

def __init__(self,master):     master.minsize(width=666, height=666) 

Will make sure your window is always at least 666 pixels large, but the user can still expand the window.

like image 31
Martin Tournoij Avatar answered Sep 28 '22 06:09

Martin Tournoij