[英]How to add a minimise button in Tkinter?
I have found many questions in stackoverflow regarding how to add a custom title bar in tkinter.我在 stackoverflow 中发现了很多关于如何在 tkinter 中添加自定义标题栏的问题。 It works for me, but none of the answers show how to add a minimise and maximise buttons on it.它对我有用,但没有一个答案显示如何在其上添加最小化和最大化按钮。 I am using a mac computer, so here is the code -我使用的是 mac 电脑,所以这是代码 -
from tkinter import *
root = Tk()
root.geometry("1000x740")
root.overrideredirect(1)
root.overrideredirect(0)
Button(root, text="Close", command=root.quit).pack()
root.mainloop()
How can I add a minimise and maximise button in this?如何在其中添加最小化和最大化按钮?
You need to call root.wm_state('iconic')
你需要调用root.wm_state('iconic')
import tkinter as tk
class My_Window(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.geometry("300x300")
tk.Button(
self, text="Minimize",
command=lambda: self.wm_state('iconic')
).pack()
if __name__ == '__main__':
app = My_Window()
app.mainloop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.