Python tkinter 网格管理器不工作,列 [英] Python tkinter grid manager not working, columns
本文介绍了Python tkinter 网格管理器不工作,列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Python 2.7 版(我知道它已经过时了)我已经搜索了几个答案,但没有找到解决方案.我正在尝试获取此标签:
Python version 2.7 (I know it's dated) I have searched throught several answers and haven't found a solution. I'm trying to get this label :
w = Label(root, text="This label", fg="red", font=("Helvetica", 16))
w.grid(row=5, column=20)
基本上任何其他列,而不是它所在的列(中心).简单地说,行有效而列无效.
to basically any other column than the one it is in (the center). Simply put the rows are working and the columns are not.
这是脚本:
from Tkinter import *
root = Tk()
root.wm_title("Title:D")
root.geometry('{}x{}'.format(500, 250))
photo = PhotoImage(file="spaz.gif")
label = Label(root, image=photo)
label.grid(row=1, column=1)
w = Label(root, text="This label", fg="red", font=("Helvetica", 16))
w.grid(row=5, column=20)
root.mainloop()
推荐答案
您可以使用 grid_columnconfigure 来显示空列.这显示了第 2 列
You can use grid_columnconfigure to show empty columns. This shows column 2
from Tkinter import *
root = Tk()
root.wm_title("Title:D")
root.geometry('{}x{}'.format(500, 300))
##photo = PhotoImage(file="spaz.gif")
label = Label(root, text="Label 1")
label.grid(row=1, column=1)
root.grid_columnconfigure(2, weight=1)
w = Label(root, text="This label", fg="red", font=("Helvetica", 16))
w.grid(row=5, column=20)
root.mainloop()
这篇关于Python tkinter 网格管理器不工作,列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文