Python 在tkinter中的框架上制作可视网格
我试图在tkinter 8.6的根目录中创建3个帧(右、中、左) 然后在每一帧中创建一个可视网格(使用“-”号)。当我尝试在第一个面板上创建网格时,收到以下错误消息 TypeError:grid_configure()至少接受1个参数(给定0个) 这是我的密码:Python 在tkinter中的框架上制作可视网格,python,tkinter,Python,Tkinter,我试图在tkinter 8.6的根目录中创建3个帧(右、中、左) 然后在每一帧中创建一个可视网格(使用“-”号)。当我尝试在第一个面板上创建网格时,收到以下错误消息 TypeError:grid_configure()至少接受1个参数(给定0个) 这是我的密码: from tkinter import * root = Tk() root.geometry("1366x768") frame_right = Frame(root,width = 1366/4,height =
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()
使用Label(parent,{some arguments})
在第一行创建一个实例,在第二行创建一个没有父实例的实例
必须更改:
Label(frame_left,text = "-",width = 10,height = 1)
Label.grid(row = i,column = j)
致:
或:
我在代码中使用了类似的东西,在主行和主列上添加可见的间距 我不认为你需要定义高度,因为文本会为你定义高度 你可能想尝试使用类似的东西
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)
Label(frame_left,text = "-",width = 10,height = 1).grid(row = i,column = j)
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)