English 中文(简体)
D. 遇到Tkinter透明度问题
原标题:Having trouble with Tkinter transparency

在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)

这是视窗7上的2.6。

最佳回答

问题是,你的法典从未允许窗户重塑自己。 睡觉导致方案停止,因此,活动休息时间被拖入,并且使活动休息时间引向窗户。

不要睡觉,而是利用活动圈子,更新每个Nilliseconds的属性,直到你获得理想的甲型透明度。

这里就是一个例子。 我也认为它是在窗户上工作的。

import Tkinter as tk

class App:
    def __init__(self):
        self.root = tk.Tk()
        self.count = 0
        b=tk.Button(text="create window", command=self.create_window)
        b.pack()
        self.root.mainloop()

    def create_window(self):
        self.count += 1
        t=FadeToplevel(self.root)
        t.wm_title("Window %s" % self.count)
        t.fade_in()


class FadeToplevel(tk.Toplevel):
       A toplevel widget with the ability to fade in   
    def __init__(self, *args, **kwargs):
        tk.Toplevel.__init__(self, *args, **kwargs)
        self.attributes("-alpha", 0.0)

    def fade_in(self):
        alpha = self.attributes("-alpha")
        alpha = min(alpha + .01, 1.0)
        self.attributes("-alpha", alpha)
        if alpha < 1.0:
            self.after(10, self.fade_in)

if __name__ == "__main__":
    app=App()
问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签