如何在 Python tkinter 中重叠小部件/框架?
在 Tkinter 应用程序中对齐和定位特定小部件有三种通用方法。假设我们想在彼此之上重叠两个或更多小部件或框架,则可以使用 place() 几何管理器。place() 几何管理器的作用是将小部件排列在网格的行和列中。通过在每个小部件中提供相同的坐标,我们可以肯定地重叠小部件。
示例
# Import the required libraries
from tkinter import *
from tkinter import ttk
# Create an instance of tkinter frame
win = Tk()
# Set the size of the tkinter window
win.geometry("700x350")
# Add a Frame
frame1= Frame(win, bg= "LightPink1")
# Add an optional Label widget
Label(frame1, text= "Welcome Folks!", font= ('Aerial 18 bold italic'), background= "white").pack(pady= 50)
frame1.place(x= 260, y= 50)
# Add a Button widget in second frame
ttk.Button(frame1, text= "Button").place(x= 260, y=50)
win.mainloop()输出
执行以上代码将显示一个窗口,其中一个标签和一个按钮小部件位于框架内。
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP