如何更改Tkinter中的标题栏

2024-09-28 17:02:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用tkinter用python制作了一个计算器,但是:

我的计算器的标题栏

Windows计算器的标题栏

我想让它看起来像Windows的


Tags: tkinterwindows计算器标题栏
1条回答
网友
1楼 · 发布于 2024-09-28 17:02:11

以下是如何创建自定义标题栏:

import tkinter as tk

root = tk.Tk()

def move_window(event):
    root.geometry('+{0}+{1}'.format(event.x_root, event.y_root))

root.overrideredirect(True) # turns off title bar, geometry
root.geometry('400x100+200+200') # set new geometry

# make a frame for the title bar
title_bar = tk.Frame(root, bg='blue', relief='raised', bd=2) # enter your colour here

# put a close button on the title bar
close_button = tk.Button(title_bar, text='X', command=root.destroy)

# a canvas for the main area of the window
window = tk.Canvas(root, bg='black')

# pack the widgets
title_bar.pack(expand=1, fill="x")
close_button.pack(side="right")
window.pack(expand=1, fill="both")

# bind title bar motion to the move window function
title_bar.bind('<B1-Motion>', move_window)

root.mainloop()

相关问题 更多 >