这是我的代码:
class Main(tk.Frame):
w = 300
h = 300
def __init__(self,parent, *args, **kwargs):
tk.Frame.__init__(self, parent, *args, **kwargs)
self.parent = parent
self.l1 = tk.Label(self, text="Iterations").grid(column=0,row=0)
self.l2 = tk.Label(self, text="angle").grid(column=0,row=1)
self.l3 = tk.Label(self, text="axiom").grid(column=0,row=2)
self.l4 = tk.Label(self, text="rule1").grid(column=0,row=3)
self.l5 = tk.Label(self, text="rule2").grid(column=0, row=4)
self.l6 = tk.Label(self, text="constants").grid(column=0, row=5)
self.e1 = tk.Entry(self, text="Iterations").grid(column=1,row=0)
self.e2 = tk.Entry(self, text="angle").grid(column=1,row=1)
self.e3 = tk.Entry(self, text="axiom").grid(column=1,row=2)
self.e4 = tk.Entry(self, text="rule1").grid(column=1,row=3)
self.e5 = tk.Entry(self, text="rule2").grid(column=1, row=4)
self.e6 = tk.Entry(self, text="constants").grid(column=1, row=5)
self.cv = tk.Canvas(width=self.w, height=self.h, bg='white')
self.cv.grid(column=2, rowspan=5)
# self.render_image()
self.grid()
我希望我的输入框和画布并排放置,但出于某种原因,标签和输入框会在画布下方绘制。我知道了;
我怎样才能并排显示它们?
答案 0 :(得分:2)
您尚未为Canvas
指定一行:
self.cv.grid(column=2, rowspan=5)
只需更新此内容即可包含第一行:
self.cv.grid(column=2, rowspan=5, row=0)
同样rowspan
应该是6而不是5。