如何在tkinter中调整照片的大小?

2024-10-04 05:24:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在设置一个带有密码输入文本框和登录按钮的登录屏幕。我想包括上面的密码文本框“trounces”标志,但图像太大,我不知道如何调整图像大小。有什么帮助吗

from tkinter import *
import tkinter as tk


class Window(Frame):

    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.master = master
        self.init_window()

    # Creation of init_window
    def init_window(self):
        photo = PhotoImage(file="trounceslogo.gif")
        quitBtn2 = Label(root, image=photo)
        quitBtn2.image = photo
        quitBtn2.pack()

        # placing a text box
        T = tk.Entry(root)
        T.pack()
        T.insert(tk.END, "Enter your password.")
        T.place(x=105, y=150)

        # changing the title of our master widget      
        self.master.title("Trounces Login")

        # allowing the widget to take the full space of the root window
        self.pack(fill=BOTH, expand=1)

        # creating a button instance
        LoginButton = Button(self, text="Login")

        # placing the button on my window
        LoginButton.place(x=175, y=200)


root = Tk()

# window size
root.geometry("400x240")

app = Window(root)
root.mainloop()  

没有错误


Tags: ofthe图像selfmaster密码inittkinter