我正在开发一个简单的 GUI,它输出一个自动复制到剪贴板的数值。一旦发生这种情况,我试图让文本“已复制”闪烁,立即出现,然后在一两秒后消失。
发生的情况是文本按照我的意愿闪烁,但显示的输出字段直到文本消失后才会更新,这不是我编写脚本的顺序。目标是让输出字段在文本出现的同时更新。
我让文本出现的方式相当粗糙,所以我非常愿意接受建议。想法和评论将不胜感激。
import sys
from win32gui import GetWindowText, EnumWindows, ShowWindow, SetForegroundWindow
import win32clipboard
import win32con
import time
import wx
from wxPython.wx import *
import itertools
from time import sleep
class MainFrame(wx.Frame):
def __init__(self,title):
wx.Frame.__init__(self, None, title="RRESI Rounder", pos=(0,0), size=(210,160))
panel=Panel(self)
class Panel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
x1=10; x2=110
y1=10; dy=30; ddy=-3
boxlength=80
self.label1 = wx.StaticText(self, label="Input Number:", pos=(x1,y1+dy*1))
self.Input = wx.TextCtrl(self, value="100.00001", pos=(x2,ddy+y1+dy*1), size=(boxlength,-1))
self.button =wx.Button(self, label="GO", pos=(9999,y1+dy*3))
self.Bind(wx.EVT_BUTTON, self.OnClick,self.button)
self.button.SetDefault()
self.label0 = wx.StaticText(self, label="Round to closest: 1/", pos=(x1,y1+dy*0))
self.Denominator = wx.TextCtrl(self, value="64", pos=(x2,ddy+y1+dy*0), size=(boxlength,-1))
self.label2 = wx.StaticText(self, label="Output Number:", pos=(x1,y1+dy*2))
self.display = wx.TextCtrl(self, value="100.00000", pos=(x2,ddy+y1+dy*2), size=(boxlength,-1))
self.display.SetBackgroundColour(wx.Colour(232, 232, 232))
self.label3 = wx.StaticText(self, label=" ", pos=(x2+7,y1+dy*2+20)) #Copied
self.label4 = wx.StaticText(self, label="", pos=(x2+7,y1+dy*2))
self.label4.SetBackgroundColour(wx.Colour(232, 232, 232))
def OnClick(self,event):
def openClipboard():
try:
win32clipboard.OpenClipboard()
except Exception, e:
print e
pass
def closeClipboard():
try:
win32clipboard.CloseClipboard()
except Exception, e:
print e
pass
def clearClipboard():
try:
openClipboard()
win32clipboard.EmptyClipboard()
closeClipboard()
except TypeError:
pass
def setText(txt):
openClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(txt)
closeClipboard()
Denominator = float(self.Denominator.GetValue())
Input=float(self.Input.GetValue())
Output=round(Input*Denominator,0)/Denominator
self.display.SetValue(str(Output))
setText(str(Output))
self.label4.SetLabel(str(Output)+"")
self.label3.SetLabel("Copied")
sleep(.5)
self.label3.SetLabel(" ")
if __name__=="__main__":
app = wx.App(redirect=False) # Error messages don't go to popup window
frame = MainFrame("RRESI Rounder")
frame.Show()
app.MainLoop()