gpt4 book ai didi

python - Tkinter 网格不工作

转载 作者:行者123 更新时间:2023-12-01 09:13:28 25 4
gpt4 key购买 nike

我想创建一个窗口,并将内容全部放在中心,但我不知道该怎么做,请帮助我。

def about_window():
win_about = tk.Toplevel(win)
win_about.geometry("340x500")
win_about.title("About Us")
win_about.resizable(0,0)
win_about.iconbitmap(r'C:/Users/810810/Desktop/python/eslogo.ico')
frame = tk.Frame(win_about)
frame.grid(row=0, column=2)

img_png = tk.PhotoImage(file = 'est.gif')
label = tk.Label(frame, image = img_png)
label.img_png = img_png
label.grid(row=0, column=1)

Message = 'Version: 1.0'
mess = tk.Label(frame, text=Message)
mess.grid(row=1, column=0)

最佳答案

我在使用 tkinter grid 时也遇到了很多问题,并且更喜欢使用 tkinter place

下面我编辑了您的代码以使用 place 而不是 gridanchor 是指您正在移动的对象的 anchor ,relx 是指相对 x 位置占其所在帧的百分比 (.5 表示帧的中间位置),rely 表示帧中 0-1 的 y 位置。

import tkinter as tk

win_about = tk.Tk()
win_about.geometry("340x500")
win_about.title("About Us")
win_about.resizable(0,0)

label = tk.Label(win_about, text="img_png", fg="black")
label.place(anchor='center', relx =.5, rely=.3)

mess = tk.Label(win_about, text='Version: 1.0', font=12)
mess.place(anchor='center', relx=.5, rely=.7)

win_about.mainloop()

关于python - Tkinter 网格不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51453576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com