Tkinter组织问题固定解决方案

2024-10-03 13:19:55 发布

您现在位置:Python中文网/ 问答频道 /正文

这三条线:

Clockframe = Frame(root, height=520, width=960)
Tempframe = Frame(root, height=520, width=960)
Bottomframe = Frame(root, height=520, width=1920)

结合这三条线:

Clockframe.grid(row=0, column=0)
Tempframe.grid(row=0, column=1)
Bottomframe.grid(row=1, columnspan=1)

给我以下结果:

Results Picture

我的目标是:

Picture with Same colorscheme as above


Tags: 目标columnrootwidthframegridrowheight
1条回答
网友
1楼 · 发布于 2024-10-03 13:19:55

columnspan=1表示Bottomframe跨越单个列。由于这将Bottomframe与第一列中的Clockframe对齐,因此第一列扩展为宽度1920。这将第二列推过第1920个像素并(可能)离开屏幕。您可以通过减小Bottomframe的宽度来确认这一点,您将看到Tempframe逐渐进入视图

因此,将columnspan=1更改为columnspan=2,使Bottomframe跨越前两列。比如说,

import tkinter as tk
root = tk.Tk()
Clockframe = tk.Frame(root, height=520, width=960, background='aqua')
Tempframe = tk.Frame(root, height=520, width=960, background='green')
Bottomframe = tk.Frame(root, height=520, width=1920, background='yellow')

Clockframe.grid(row=0, column=0)
Tempframe.grid(row=0, column=1)
Bottomframe.grid(row=1, columnspan=2)

root.mainloop()

相关问题 更多 >