[英]Making a visual grid on a Frame in tkinter
I'm tring to create 3 Frames (right, center, left) in the root in tkinter 8.6 and then making a visual grid ( using "-") in each frame. 我正在尝试在tkinter 8.6的根目录中创建3个框架(右,中,左),然后在每个框架中创建可视网格(使用“-”)。 I get the following error message when I try to make the grid on the first panel. 当我尝试在第一个面板上创建网格时,出现以下错误消息。
TypeError: grid_configure() takes at least 1 argument (0 given). TypeError:grid_configure()至少接受1个参数(给定0)。
Here is my code: 这是我的代码:
from tkinter import *
root = Tk()
root.geometry("1366x768")
frame_right = Frame(root,width = 1366/4,height = 768bg = "powder blue")
frame_right.pack(side = LEFT)
frame_center = Frame(root,width = 1366/2,height = 768,bg = "red")
frame_center.pack(side = LEFT)
frame_left = Frame(root,width = 1366/4,height = 768,bg = "steel blue")
frame_center.pack(side = LEFT)
for i in range(0,10):
for j in range(0,20):
Label(frame_left,text = "-",width = 10,height = 1)
Label.grid(row = i,column = j)
root.mainloop()
With Label(parent, {some arguments})
, you create an instance on the first line, on the second you create an instance with no parent. 使用Label(parent, {some arguments})
,在第一行上创建一个实例,在第二行上创建没有父级的实例。
Must be change: 必须更改:
Label(frame_left,text = "-",width = 10,height = 1)
Label.grid(row = i,column = j)
to: 至:
label = Label(frame_left,text = "-",width = 10,height = 1)
label.grid(row = i,column = j)
or: 要么:
Label(frame_left,text = "-",width = 10,height = 1).grid(row = i,column = j)
I have something similar I use in my code to add visible spacing on my main row and column. 我在代码中使用了类似的东西,以在主行和主列上添加可见的间距。
I don't think you need to define height because the text will do that for you. 我认为您无需定义高度,因为文本会为您做到这一点。
You might want to try using something like this. 您可能想尝试使用类似这样的东西。
for col_num in range(20):
spacer=Label(root, text=str(col_num))
#replace root with your frame
#you can replace str(col_num) with your "-"
spacer.grid(row = 0, column = col_num)
root.columnconfigure(col_num, minsize=10)
for row_num in range(10):
spacer=Label(root, text=str(row_num)) #replace root with your frame
spacer.grid(row = row_num, column = 0)
root.rowconfigure(row_num, minsize=10)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.