第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

自定義標(biāo)題欄和關(guān)閉按鈕 Tkinter

自定義標(biāo)題欄和關(guān)閉按鈕 Tkinter

元芳怎么了 2022-10-25 15:17:04
我在stackoverflow上找到了這段代碼:from tkinter import *root=Tk()root.overrideredirect(True) # turns off title bar, geometryroot.geometry('400x100+200+200') # set new geometry# make a frame for the title bartitle_bar = Frame(root, bg='#2e2e2e', relief='raised', bd=2,highlightthickness=0)# put a close button on the title barclose_button = Button(title_bar, text='X', command=root.destroy,bg="#2e2e2e",padx=2,pady=2,activebackground='red',bd=0,font="bold",fg='white',highlightthickness=0)# a canvas for the main area of the windowwindow = Canvas(root, bg='#2e2e2e',highlightthickness=0)# pack the widgetstitle_bar.pack(expand=1, fill=X)close_button.pack(side=RIGHT)window.pack(expand=1, fill=BOTH)xwin=Noneywin=None# bind title bar motion to the move window functiondef move_window(event):    root.geometry('+{0}+{1}'.format(event.x_root, event.y_root))def change_on_hovering(event):    global close_button    close_button['bg']='red'def return_to_normalstate(event):    global close_button    close_button['bg']='#2e2e2e'title_bar.bind('<B1-Motion>', move_window)close_button.bind('<Enter>',change_on_hovering)close_button.bind('<Leave>',return_to_normalstate)root.mainloop()問題是窗口的移動很奇怪,有沒有辦法通過更改代碼來解決它?
查看完整描述

1 回答

?
斯蒂芬大帝

TA貢獻(xiàn)1827條經(jīng)驗 獲得超8個贊

使固定:


from tkinter import *

from webbrowser import *


root=Tk()

root.overrideredirect(True) # turns off title bar, geometry

root.geometry('400x100+200+200') # set new geometry

root.attributes('-topmost', True)


lastClickX = 0

lastClickY = 0


def SaveLastClickPos(event):

    global lastClickX, lastClickY

    lastClickX = event.x

    lastClickY = event.y


def Dragging(event):

    x, y = event.x - lastClickX + root.winfo_x(), event.y - lastClickY + root.winfo_y()

    root.geometry("+%s+%s" % (x , y))


# make a frame for the title bar

title_bar = Frame(root, bg='#2e2e2e', relief='raised', bd=2,highlightthickness=0)


# put a close button on the title bar

close_button = Button(title_bar, text='X', command=root.destroy,bg="#2e2e2e",padx=2,pady=2,activebackground='red',bd=0,font="bold",fg='white',highlightthickness=0)


window = Canvas(root, bg='#2e2e2e',highlightthickness=0)


# pack the widgets

title_bar.pack(expand=1, fill=X)

close_button.pack(side=RIGHT)

window.pack(expand=1, fill=BOTH)


title_bar.bind('<Button-1>', SaveLastClickPos)

title_bar.bind('<B1-Motion>', Dragging)

root.mainloop()


查看完整回答
反對 回復(fù) 2022-10-25
  • 1 回答
  • 0 關(guān)注
  • 118 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號