如何让界面布局适合其他屏幕分辨率?

问题描述 投票:0回答:1

如何使其他屏幕尺寸(分辨率)不同的计算机上程序中的界面布局与我的计算机上相同。例如:我在我的计算机上运行该程序,界面一切正常,但是当我在另一台(较小或较大)计算机上运行它时,界面与我的不一样。如何才能让其他电脑上的界面和我的一样呢? 将 tkinter 导入为 tk

from PIL import Image, ImageTk


def open_second_window():
    second_window = tk.Toplevel(root)
    second_window.title("window")
    second_window.state('zoomed')

    image_path = "1.jpg"
    image = Image.open(image_path)
    photo = ImageTk.PhotoImage(image)

    label = tk.Label(second_window, image=photo)
    label.image = photo 
    label.pack(fill=tk.BOTH, expand=True)
    label.place(x=770, y=0)

    button = tk.Button(second_window,height=4, width=12, font='Times 31', text="ONE", command=lambda: open_four_window(second_window))

    button.place(x=308, y=82, anchor='ne')
    button1 = tk.Button(second_window,height=4, width=12, font='Times 31', wraplength=289, text="TWO", command=open_five_window)
    button1.place(x=688, y=82, anchor='ne')
    button = tk.Button(second_window,height=4, width=12, font='Times 31', text="THREE", command=open_threee_window)
    button.place(x=308, y=352, anchor='ne')
    button1 = tk.Button(second_window,height=4, width=12, font='Times 31', text="FOUR", command=open_threetenfive_window)
    button1.place(x=688, y=352, anchor='ne')


    tk.Label(second_window, font='Times 30', text="text", fg="red").place(x=150, y=30)


    third_window.grab_set()
def open_four_window(second_window):
    second_window.destroy()

    four_window = tk.Toplevel(root)
    four_window.title("win")
    four_window.state('zoomed')

    image_path = "2.jpg"
    image = Image.open(image_path)
    photo = ImageTk.PhotoImage(image)

    label = tk.Label(four_window, image=photo)
    label.image = photo  
    label.pack(fill=tk.BOTH, expand=True)
    label.place(x=0, y=0)


    button = tk.Button(four_window,height=1, width=33, font='Times 31', text="Start", command=lambda: open_second_window())
    button.place(x=768, y=720, anchor='ne')
    button1 = tk.Button(four_window,height=1, width=33, font='Times 31', text="Exit", command=Close)
    button1.place(x=1536, y=720, anchor='ne')



    third_window.grab_set()

///

root = tk.Tk()
root.title("menu")
root.state('zoomed')


image_path = "40.jpg"
image = Image.open(image_path)
photo = ImageTk.PhotoImage(image)
image.thumbnail((1, 1))

label = tk.Label(root, image=photo)
label.pack(fill=tk.BOTH, expand=True)
label.place(x=-3, y=0)

def Close(): 
    root.destroy() 

button = tk.Button(root,height=1, width=33, font='Times 31', text="Start", command=lambda: open_second_window())
button.place(x=768, y=720, anchor='ne')
button1 = tk.Button(root,height=1, width=33, font='Times 31', text="Exit", command=Close)
button1.place(x=1536, y=720, anchor='ne')


tk.Label(root, font='Times 30', text="text", fg="red").place(x=150, y=30)
tk.Label(root, font='Times 30 italic', text="description").place(x=600, y=77)

root.mainloop()
python python-3.x windows debugging tkinter
1个回答
0
投票

您可能会遇到此问题,因为您将 x 和 y 位置设置为固定。如果您希望组件的尺寸根据屏幕分辨率而变化,可以使用带有 relwidth 和 relheight 参数的 place 函数。 前任。 按钮.place(relx=0.5,rely=0.9,relwidth=0.25,relheight=0.1,anchor='ne')

© www.soinside.com 2019 - 2024. All rights reserved.