相关疑难解决方法(0)

在Tkinter python中放置相对于父窗口的子窗口

我有一个包含按钮的父小部件。当按钮被按下时,我想在父小部件的正下方打开一个无边框(即没有 Windows 装饰按钮)窗口,与它的左侧对齐。我很困惑,设置窗口位置的唯一方法(似乎)正在使用,.geometry()但更糟糕的是,我似乎无法获得父小部件的绝对坐标 - 我需要.geometry(),只有从父小部件的偏移量父母。到目前为止,我的代码是:

# This is the child which appears when the button is pressed.
class ChildPopUpWindow(Frame):
    def __init__(self, parentWgdt):
        win = Toplevel(parentWgdt)
        geom = str(parentWgdt.winfo_x()) + '+' + str(parentWgdt.winfo_y() + parentWgdt.winfo_height())
        win.overrideredirect(1) # No win decoration.
        win.bd = 10
        win.relief = GROOVE
        win.geometry( geom )
        Frame.__init__(self, win)
        # etc. etc.

     # ... and this is the handler for the button being pressed.
     def onDropDown(self):
        popUp = ChildPopUpWindow(self)
Run Code Online (Sandbox Code Playgroud)

这确实会弹出一个窗口,但相对于桌面,而不是父小部件。据我所知,它似乎也没有考虑边框的厚度和浮雕。任何人都可以提供一种可以做到这一点的方法吗?是.geometry()要走的路还是有更好的方法?

python window tkinter coordinates

6
推荐指数
1
解决办法
6237
查看次数

Tkinter透明度有问题

我在TKinter中制作顶级小部件时遇到了问题.由于某种原因,窗口小部件根本不会淡入,然后它将显示在任务栏中,但只有在单击运行此命令的按钮两次之后(它不应该在任务栏中).

负责这些问题的代码.

    Alpha = 0.0
    w1.attributes("-alpha", Alpha)
    w1.wm_geometry("+" + str(X) + "+" + str(M))
    while 1.0 > Alpha :
        Alpha = Alpha + 0.01
        w1.attributes("-alpha", Alpha)
        sleep(0.005)
Run Code Online (Sandbox Code Playgroud)

这是Windows 7上的python 2.6.

python transparency tkinter windows-7 fadein

2
推荐指数
1
解决办法
5297
查看次数

如何在Tkinter中创建淡出效果?我的代码崩溃了

我正在通过overrideredirect在Tkinter中构建一个带有自定义窗口的应用程序.我将自行设计的X按钮绑定到下面的功能.使用我的按钮关闭应用程序工作正常,它确实淡出,但几秒钟后窗口重新出现,卡在一个循环(这就是它的样子)和崩溃.它应该退出,这是我在添加淡出循环之前所做的.有人能告诉我为什么程序重新出现然后在关闭应用程序时崩溃或为淡出效果提供更好的替代方案(我知道有更复杂的工具包但我需要在这种情况下使用Tkinter)?

谢谢

def CloseApp(event):
if InProgress==False: #InProgress boolean defined elsewhere in program
    if tkMessageBox.askokcancel("Quit","Do you really wish to quit?"):
        n=1
        while n != 0:
            n -= 0.1
            QuizWindow.attributes("-alpha", n)
            time.sleep(0.02)                                  
        Window.destroy() #I've also tried using the quit() method, not that it would make a difference
else:
    if tkMessageBox.askokcancel("Quit"," If you quit now you will lose your progress and have to start again. Are you sure you want to quit?"):
        n=1
        while n != 0:
            n -= 0.1
            QuizWindow.attributes("-alpha", n)
            time.sleep(0.02) …
Run Code Online (Sandbox Code Playgroud)

python tkinter

2
推荐指数
1
解决办法
4370
查看次数

标签 统计

python ×3

tkinter ×3

coordinates ×1

fadein ×1

transparency ×1

window ×1

windows-7 ×1