python使用tkinter可以在多个操作系统_python tkinter,多个项目p

pack有一些选项,允许您控制要使用的控件的哪一面、填充和其他内容。例如,要从左到右打包小部件,可以使用widget.pack(side='left')。所有这些选择在许多地方都有很好的文档记录。在

下面是一个快速示例,在顶部显示一行按钮,右侧显示一列标签:import Tkinter as tk

class Example(tk.Frame):

def __init__(self, parent):

tk.Frame.__init__(self, parent)

self.toolbar = tk.Frame(self, borderwidth=1, relief="raised")

self.labels = tk.Frame(self, borderwidth=1, relief="raised")

self.text = tk.Text(self, width=80, height=20)

self.toolbar.pack(side="top", fill="x")

self.labels.pack(side="right", fill="y")

self.text.pack(side="left", fill="both", expand=True)

for i in range(5):

button = tk.Button(self.toolbar, text="Button %d" %i)

button.pack(side="left")

for i in range(5):

label = tk.Label(self.labels, text="Label %d" %i)

label.pack(side="top", fill="x", padx=8)

if __name__ == "__main__":

root = tk.Tk()

Example(root).pack(fill="both", expand=True)

root.mainloop()


版权声明:本文为weixin_35825858原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。