【问题标题】:Python: Is there a way to change the tkinter window shape?Python:有没有办法改变 tkinter 窗口的形状?
【发布时间】: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 中,您可以将特定颜色设置为透明,因此如果您将边缘设置为该颜色,它看起来就像是不同的形状。要制作圆形按钮,您必须自己根据图像制作按钮小部件。

标签: python tkinter


【解决方案1】:

您好,我认为这可以帮助您:

Different shapes of windows in tkinter

Non-standard windows with Tkinter?

改变按钮样式的一个简单方法是使用图片!

【讨论】:

  • 不客气@HaloDonutsJ,如果我能帮到你,请点赞。
  • 如果我有,我没有 15 名声望
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-26
  • 1970-01-01
  • 2023-01-25
  • 1970-01-01
  • 2021-04-28
  • 2023-02-10
  • 1970-01-01
相关资源
最近更新 更多