簡體   English   中英

如何使用網格方法Python Tkinter在同一單元格中添加多個功能

[英]How to add more than one feature into the same cell using the grid method, Python Tkinter

可能會有這樣的問題,但我找不到。 我想在同一個單元格中有多個條目或標簽等,而又不重疊。 我希望你明白我的意思。 有任何想法嗎?

將所需數量的項目放入框架中,然后將框架放入網格單元中。

import tkinter as tk

root = tk.Tk()

# some random widgets, for illustrative purposes
l0 = tk.Label(root, text="Cell 0,0", borderwidth=1, relief="solid")
l1 = tk.Label(root, text="Cell 0,1", borderwidth=1, relief="solid")
l2 = tk.Label(root, text="Cell 1,0", borderwidth=1, relief="solid")
l3 = tk.Label(root, text="Cell 1,1", borderwidth=1, relief="solid")
l4 = tk.Label(root, text="Cell 1,2", borderwidth=1, relief="solid")

# create a frame for one of the cells, and put
# a label and entry widget in it
f1 = tk.Frame(root, borderwidth=1, relief="solid")
l5 = tk.Label(f1, text="Cell 0,2")
e1 = tk.Entry(f1)

# put the label and entry in the frame:
l5.pack(side="top", fill="both", expand=True)
e1.pack(side="top", fill="x")

# put the widgets in the root
l0.grid(row=0, column=0, padx=2, pady=2, sticky="nsew")
l1.grid(row=0, column=1, padx=2, pady=2, sticky="nsew")
f1.grid(row=0, column=2, padx=2, pady=2, sticky="nsew")
l2.grid(row=1, column=0, padx=2, pady=2, sticky="nsew")
l3.grid(row=1, column=1, padx=2, pady=2, sticky="nsew")
l4.grid(row=1, column=2, padx=2, pady=2, sticky="nsew")

root.mainloop()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM