无边界风背后的对话

2024-10-04 11:23:07 发布

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

我在尝试在主窗口顶部显示默认的tkinter askyesno对话框时遇到问题,它没有边框(我使用的是overrideredirect(1))。对我来说,有一个无边界的窗口是必须的。在

对话框总是在主窗口后面打开。创建一个自定义对话框,也无边界似乎可以工作,但我想知道是否有办法使默认的askYesNo对话框出现在无边界窗口的顶部。我在Raspbian(Debian的一个版本)上运行代码。在

python代码附在下面:

from Tkinter import *
from tkMessageBox import *

def imageLabelPressed():

    print("Call button pressed")
    selected = lb.get(whichSelected())

    if (askyesno("Call", "Do you want to call %s?" % (selected) )):
        print("Call started")
    else:
        print("Cancel call")

win = Tk()
win.geometry('800x480')

backgroundImg = PhotoImage(file = "background.png")
backgroundLabel = Label(win, image = backgroundImg)
backgroundLabel.place(x=0, y=0, relwidth=1, relheight=1)

lb=Listbox(win, height=9)
lb.pack(side = LEFT, fill = BOTH, expand = 1)

callImage = PhotoImage(file = "callButton.png")
dButt = Label(win, text = "Some text", relief = FLAT, highlightthickness = 0, border = 0, image = callImage)
dButt.bind("<Button-1>", imageLabelPressed)
dButt.pack()

win.overrideredirect(1)
mainloop()

谢谢!在


Tags: 代码fromimportcallwin对话框边界print