0
我一個簡單的GUI,其輸出將被自動複製到剪貼板的數值工作GUI。我試圖讓文本「複製」一旦發生這種情況,立即出現,然後在一兩秒鐘後消失。瞬態文本與wxPython的
會發生什麼是文字閃爍,我想它,但所顯示的輸出字段不後才文本消失,這是不是我有腳本的順序更新。目標是讓輸出字段在文本出現的同一瞬間顯示更新。
我已經出現在文本的方式是比較簡陋,所以我給的建議非常開放。想法和意見將不勝感激。
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()
太好了!謝謝。 你有什麼建議使用,而不是睡覺? – Mike
wxTimer可能是一個更好的選擇,如果你不想阻止 –