Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
380 views
in Technique[技术] by (71.8m points)

python - How can I resize the root window in 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) + "
")
        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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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-


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...