【发布时间】:2021-02-27 03:42:43
【问题描述】:
我使用 tkinter 创建了一个无边框窗口,我想知道是否有办法将形状更改为圆角矩形?以及使按钮也变得圆润? 这是我当前的代码:
from tkinter import *
import tkinter as tk
root = tk.Tk()
root.overrideredirect(1)
window_width = root.winfo_reqwidth()
window_height = root.winfo_reqheight()
print("Width", window_width, "Height", window_height)
# Change the position of the window on screen
position_right = int(root.winfo_screenwidth() / 2 - window_width / 2)
position_down = int(root.winfo_screenheight() / 2 - window_height / 2)
root.geometry("+{}+{}".format(position_right, position_down))
# Change how it looks look into changing the shape and any animations we could add
frame = Frame(root, width=500, height=150,
borderwidth=2, relief=RAISED, bg="#0D0E50")
frame.pack_propagate(False)
frame.pack()
b_minimize = Button(frame, text="<", height=10, bg="light blue", fg="white", borderwidth=1, command=root.quit())
b_minimize.place(x=0, y=0)
root.mainloop()
【问题讨论】:
-
不,无法更改窗口形状。但是在 Windows 中,您可以将特定颜色设置为透明,因此如果您将边缘设置为该颜色,它看起来就像是不同的形状。要制作圆形按钮,您必须自己根据图像制作按钮小部件。