user2332665 user2332665 - 1 year ago 229
Python Question

Setting the window to a fixed size with Tkinter

This program will create a window where a message is displayed according to a check box.

from Tkinter import *

class App:
def __init__(self,master):
self.var = IntVar()
frame = Frame(master)
f2 = Frame(master,width=200,height=100)
button = Checkbutton(frame,text='show',variable=self.var,command=self.fx)
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():

top = Tk()
app = App(top)

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

Answer Source

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)

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. :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download