Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I resize the root window in Tkinter?

Tags:

python

tkinter

from Tkinter import *
import socket, sys
from PIL import Image, ImageTk

root = Tk()
root.title("Whois Tool")
root.resizable(0, 0)

text = Text()
text1 = Text()

image = Image.open("hacker2.png")
photo = ImageTk.PhotoImage(image)

label = Label(root, image=photo)
label.pack()


text1.config(width=15, height=1)
text1.pack()

def button1():
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect(("com.whois-servers.net", 43))
        s.send(text1.get("1.0", END) + "\r\n")
        response = ''
        while True:
            a = s.recv(4096)
            response += a
            if a == '':
                break
        s.close()
        text.insert(END, response)

def clear():
        text.delete("1.0", END)


b = Button(root, text="Enter", width=10, height=2, command=button1)
b.pack()

c = Button(root, text="Clear", width=10, height=2, command=clear)
c.pack()

scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)
text.config(width=60, height=15)
text.pack(side=LEFT, fill=Y)
scrollbar.config(command=text.yview)
text.config(yscrollcommand=scrollbar.set)


root.mainloop()

How can I resize the root window, or how can I resize an image to fit with the root window or button or lable and ect.. thanks

like image 867
sourD Avatar asked Feb 14 '10 12:02

sourD


People also ask

How do I resize a Tk window?

You can set the size of Tkinter window by calling geometry() function on the window with width and height string passed as argument.

How do I change the default window size in tkinter?

In Tkinter, minsize() method is used to set the minimum size of the Tkinter window. Using this method a user can set window's initialized size to its minimum size, and still be able to maximize and scale the window larger. This method is used to set the maximum size of the root window.

What is root resizable in Python?

resizable() method is used to allow Tkinter root window to change it's size according to the users need as well we can prohibit resizing of the Tkinter window. So, basically, if user wants to create a fixed size window, this method can be used.

Which method is used to change the size of window in Python?

resizeTo() The Window. resizeTo() method dynamically resizes the window.


1 Answers

For a 500x500 window you would use

root.geometry("500x500")

As for image resizing, I do not believe Tkinter supports it. You would have to use a library such as PIL to resize the image to the window resolution. -example resize code-

like image 148
Sleepingrock Avatar answered Sep 19 '22 13:09

Sleepingrock