python tkinter grid布局例子

qjxc2011 2021-08-13 18:20:57
import tkinter as tk
import tkinter.ttk as ttk
import tkinter.scrolledtext as tksc

root = tk.Tk()
root.title("grid布局")



def remove8():
    box.delete(1.0, tk.END)
    info = btn8.grid_info()
    box.insert(1.0, info)


def getInfo_a():
    box.delete(1.0, tk.END)
    info = btn0.grid_info()
    box.insert(1.0, info)


def getInfo_b():
    box.delete(1.0, tk.END)
    info = btn1.grid_info()
    box.insert(1.0, info)


def getInfo_c():
    box.delete(1.0, tk.END)
    info = btn2.grid_info()
    box.insert(1.0, info)


def getInfo_d():
    box.delete(1.0, tk.END)
    info = btn3.grid_info()
    box.insert(1.0, info)


def getInfo_A():
    box.delete(1.0, tk.END)
    info = btn4.grid_info()
    box.insert(1.0, info)


def getInfo_B():
    box.delete(1.0, tk.END)
    info = btn5.grid_info()
    box.insert(1.0, info)


def getInfo_C():
    box.delete(1.0, tk.END)
    info = btn6.grid_info()
    box.insert(1.0, info)


def getInfo_D():
    box.delete(1.0, tk.END)
    info = btn7.grid_info()
    box.insert(1.0, info)


def getInfo_8():
    box.delete(1.0, tk.END)
    info = btn8.grid_info()
    box.insert(1.0, info)


def getInfo_9():
    box.delete(1.0, tk.END)
    info = btn9.grid_info()
    box.insert(1.0, info)


btn0 = ttk.Button(root, text="a", command=getInfo_a)
btn1 = ttk.Button(root, text="b", command=getInfo_b)
btn2 = ttk.Button(root, text="c", command=getInfo_c)
btn3 = ttk.Button(root, text="d", command=getInfo_d)

btn4 = ttk.Button(root, text="A", command=getInfo_A)
btn5 = ttk.Button(root, text="B", command=getInfo_B)
btn6 = ttk.Button(root, text="C", command=getInfo_C)
btn7 = ttk.Button(root, text="D", command=getInfo_D)
btn8 = ttk.Button(root, text="横跨", width=20, command=getInfo_8)
btn9 = ttk.Button(root, text="竖跨", command=getInfo_9)
box = tksc.ScrolledText(root, width=80, height=5)

btn0.grid(row=0, column=0, padx=2, pady=2)
btn1.grid(row=0, column=1, padx=2, pady=2)
btn2.grid(row=0, column=2, padx=2, pady=2)
btn3.grid(row=0, column=3, padx=2, pady=2)

btn4.grid(row=1, column=0, padx=2, pady=2)
btn5.grid(row=1, column=1, padx=2, pady=2)
btn6.grid(row=1, column=2, padx=2, pady=2)
btn7.grid(row=1, column=3, padx=2, pady=2)

btn8.grid(row=2, column=0, padx=2, pady=2, columnspan=3)
btn9.grid(row=0, column=4, padx=2, pady=2, rowspan=3)
box.grid(row=3, column=0, padx=2, pady=2, columnspan=5)

root.mainloop()
...全文
1001 回复 打赏 收藏 举报
写回复
回复
切换为时间正序
请发表友善的回复…
发表回复
相关推荐
发帖
其他
加入

236

社区成员

其他产品/厂家
社区管理员
  • 其他
申请成为版主
帖子事件
创建了帖子
2021-08-13 18:20
社区公告
暂无公告