用python写一个界面,要有四个板块,垂直分布
时间: 2024-03-15 12:47:44 浏览: 18
好的,以下是一个使用Tkinter实现的带有四个板块的垂直分布的界面示例:
```python
import tkinter as tk
# 创建主窗口
root = tk.Tk()
# 设置窗口标题
root.title("Four Panels GUI")
# 设置窗口大小
root.geometry("600x400")
# 创建四个Frame作为四个板块
frame1 = tk.Frame(root, bg="red", height=100, width=600)
frame2 = tk.Frame(root, bg="green", height=100, width=600)
frame3 = tk.Frame(root, bg="blue", height=100, width=600)
frame4 = tk.Frame(root, bg="yellow", height=100, width=600)
# 将四个Frame按照顺序垂直排列
frame1.pack(side=tk.TOP, fill=tk.X)
frame2.pack(side=tk.TOP, fill=tk.X)
frame3.pack(side=tk.TOP, fill=tk.X)
frame4.pack(side=tk.TOP, fill=tk.X)
# 进入主循环
root.mainloop()
```
这个例子中,我们创建了四个Frame组件,并使用`pack()`方法将它们按照顺序垂直排列,每个Frame的高度为100像素,宽度为600像素。你可以根据自己的需求修改Frame的大小、颜色等。