python - Tkinter 网格不工作
问题描述
我想创建一个窗口,内容都在中心,但我不知道该怎么做,请帮助我。
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
而不是grid
. 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()
推荐阅读
- testflight - 苹果更新后应用程序未显示在应用程序 Testflight 中
- html - jQuery - 在 HTML 字符串的元素内插入文本
- mysql - Codeigniter 中的 LEFT JOIN 显示语法错误
- java - ASM ByteCode 方法局部变量
- django - 如何在django中根据status=True排列数据
- css - Bootstrap 5 - 在网格显示中对齐内容
- reactjs - 当我从 Context 检索值时,我没有得到任何数据
- java - 如何在 Android Studio 的“短信内容提供者”中读取我自己发送的短信
- reactjs - 将更新的状态从父母传递给孩子
- permissions - 如何授予 AdMob 互联网访问权限?