button3 = tk.Button(frame1, text = "Button3") button3.pack(padx = 10, pady = 10) frame2 = tk.Frame(frame1, bd=5, relief=tk.RIDGE, bg="black") frame2.pack(fill=tk.X) button4 = tk.Button(frame1, text = "Button1") button4.pack(padx = 10, pady = 10) button5 = tk...
f1 = tk.Frame(window,width=150,height=150,bg='blue',borderwidth=2) f2 = tk.Frame(window,width=150,height=150,bg='red',borderwidth=2) f3 = tk.Frame(window,width=150,height=150,bg='gray',borderwidth=2) f4 = tk.Frame(window,width=150,height=150,bg='yellow',borderwidth=2) f1....
Button(frame, text="按钮2") button2.pack() button3 = tk.Button(frame, text="按钮3") button3.pack() 在上面的示例中,我们首先创建了一个 Frame 容器frame ,然后使用 pack() 方法将它添加到了 root 窗口中。接下来,我们创建了三个按钮 button1、 button2 和button3 ,并使用 pack() 方法排列它们...
tk.Button(windows,text=i).pack(side='left',expand='yes',fill='y') windows.mainloop() 1. 2. 3. 4. 5. 6. 7. case1:拓展 这里使用了frame,在父窗口分别建立了两个矩形区域,而避免放置时出现左右并排的情况 #for 循环宽体text内容,进行排布 import tkinter as tk windows=tk.Tk() f1=tk.Fram...
frame = tk.Frame(root) frame.pack() # 使用Pack布局将容器添加到窗口中 # 创建三个按钮并使用Pack布局排列它们 button1 = tk.Button(frame, text="按钮1") button1.pack() button2 = tk.Button(frame, text="按钮2") button2.pack() button3 = tk.Button(frame, text="按钮3") ...
frame = tk.Frame(root, width=200, height=100, bd=1, relief=tk.SOLID) frame.pack() #在Frame中添加其他组件 label = tk.Label(frame, text="这是一个Frame示例") label.pack() # 运行主循环 root.mainloop() ``` 3. Frame组件的常用属性 ...
root.title("使用Frame组件示例") # 创建Frame组件 frame = tk.Frame(root, width=200, height=100, bd=1, relief=tk.SOLID) frame.pack() #在Frame中添加其他组件 label = tk.Label(frame, text="这是一个Frame示例") label.pack() # 运行主循环 ...
frame.pack() win.mainloop() 2、不同的Frame使用不同的布局 #-*- encoding=utf-8 -*-importtkinterfromtkinterimport*if__name__=='__main__':passw= tkinter.Tk()#窗口w.title('测试')#标题w.geometry('200x100+30+30')#大小以及位置frame = Frame()#定义容器Button( ...
# 导入模块import tkinter as tkfrom tkinter import ttkimport tkinter.messagebox as tm # 创建窗口对象root = tk.Tk()# 窗口标题root.title("窗口")# 设置窗口大小及位置root.geometry("400x200+500+200")note = ttk.Notebook(root)note.pack(fill="both", expand=True)frm1 = ttk.Frame(note)label1 ...
window = tk.Tk() for i in range(3): for j in range(3): frame = tk.Frame( master=window, relief=tk.RAISED, borderwidth=1 ) frame.grid(row=i, column=j) label = tk.Label( master=frame, text=f"Row {i}\nColumn {j}"