Python Tkinter格栅不工作

Python Tkinter格栅不工作,python,tkinter,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'

我想创建一个窗口,所有内容都在中心,但我不知道该怎么做,请帮助我

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)

我在
tkintergrid
方面也遇到了很多问题,我更喜欢使用
tkinterplace

下面我编辑了您的代码以使用
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()
这应该行得通(它在我的Ubuntu16上用Python2.7运行)

它打开两个窗口,这是想要的还是不想要的

它在中间显示一个图像,在下面显示您的文本

它通过添加“”字符串来工作,就像neeraj nair建议的那样。(他建议放置任何东西来调整布局。)

(@Elvis Fan:我知道你用的是windows,但它也应该适用于windows。)


清楚地解释您的问题当我将“mess.grid(row=1,column=0)”更改为“mess.grid(row=1,column=1)”时,标签和mess位于左侧,但我希望位于中间。第0列上应该有一些内容……因此在(0,0)上放置任何徽标或任何内容。我尝试在(0,0)中放置一些内容,但是仍然有相同的结果。移除框架并使用win_。抱歉,我尝试了你的方法,但没有显示任何内容。忘记打包框架。我简化了它,这样你就可以直接复制粘贴它了
import Tkinter as tk
def about_window():
    win_about = tk.Toplevel()
    win_about.geometry("340x500")
    win_about.title("About Us")
    win_about.resizable(0,0)
    frame = tk.Frame(win_about)
    frame.grid(row=0, column=2)
    for i in range(0,12):
        Message = " "
        mess = tk.Label(frame, text=Message)
        mess.grid(row=i, column=0)
    img_png = tk.PhotoImage(file = 'gbsnode.png')
    label = tk.Label(frame, image = img_png)
    label.img_png = img_png
    label.grid(row=21, column=2)
    Message = '                                '
    mess = tk.Label(frame, text=Message)
    mess.grid(row=23, column=1)
    Message = 'Version 1'
    mess = tk.Label(frame, text=Message)
    mess.grid(row=24, column=2)
    frame.mainloop()
about_window()
while True:
    pass