【问题标题】:How do I reflect the background of a window in tkinter without reflecting the things inside the window?如何在 tkinter 中反映窗口的背景而不反映窗口内的东西?
【发布时间】:2022-12-11 00:24:51
【问题描述】:
我想删除 tkinter 窗口的所有背景,并仍然保留我在窗口中所做的所有其他事情
from tkinter import *
win = Tk()
win.geometry("500x500")
Button = Button(win, text="Button", font=("ariel", 20))
Button.pack()
win.mainloop()
我想让这个按钮留下来,背景变透明
【问题讨论】:
标签:
python
tkinter
background
transparent
【解决方案1】:
您可以使用销毁功能
Tkinter 中的 destroy() 方法销毁一个小部件。它在控制相互依赖的各种小部件的行为时很有用。此外,当某个进程因某些用户操作而完成时,我们需要销毁 GUI 组件以释放内存并清除屏幕。 destroy() 方法实现了这一切。
在下面的示例中,我们有带有 3 个按钮的屏幕。单击第一个按钮将关闭窗口本身,而单击第二个按钮将关闭第一个按钮,依此类推。这种行为是通过使用 destroy 方法来模拟的,如下面的程序所示。
例子
from tkinter import *
from tkinter.ttk import *
#tkinter window
base = Tk()
#This button can close the window
button_1 = Button(base, text ="I close the Window", command = base.destroy)
#Exteral paddign for the buttons
button_1.pack(pady = 40)
#This button closes the first button
button_2 = Button(base, text ="I close the first button", command =
button_1.destroy)
button_2.pack(pady = 40)
#This button closes the second button
button_3 = Button(base, text ="I close the second button", command =
button_2.destroy)
button_3.pack(pady = 40)
mainloop()