In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "python optical simulation learning wxpython how to create hand speed test program", the explanation content in the article is simple and clear, easy to learn and understand, please follow the idea of Xiaobian slowly in-depth, together to study and learn "python optical simulation learning wxpython how to create hand speed test program"!
Scrolling bars are naturally known to everyone, and can show changes in data very intuitively, or can change certain values very easily.
Previously, when introducing buttons, static text, and input text, these three controls were relatively boring, so this time we adopted a demand-driven model. If you want to write software that detects typing speed and displays it intuitively via a scroll bar, how do you write it?
We need roughly three controls: a text input control to enter text; a static text control to display speed; and a scroll bar to dynamically display speed. At the same time, you also need to know the system time, in short, the code is as follows
import wximport time #time module class testFrame(wx.Frame): def __init__(self, parent=None, title="test",size=(300,320)): wx.Frame.__ init__(self,parent=parent, title=title,size=size) self.SetBackgroundColour(wx.Colour(222,222,222)) self.timeStart=0 self.count=0 self.setText = wx.TextCtrl(self,value="input", pos=(10,10),size=(240,240),style=wx.TE_MULTILINE) self.ratioSlider = wx.Slider(self, minValue=0,maxValue=20,pos=(260,10),size=(20,220), style=wx.SL_VERTICAL|wx.SL_INVERSE) self.ratioLabel = wx.StaticText(self,-1,"0", pos=(260,240),size=(20,10)) self.setText.Bind(wx.EVT_TEXT,self.onCount) self.setText.Bind(wx.EVT_TEXT_ENTER,self.onText) def onText(self,evt): self.count = 0 #When you hit Enter, the count is cleared self.timeStart=time.time() #Current time in seconds def onCount(self,evt): self.count += 1 if self.timeStart==0: self.timeStart = time.time() ratio = self.count/(time.time()-self.timeStart) self.ratioSlider.SetValue(ratio) self.ratioLabel.SetLabel(str(ratio))if __name__ == '__main__': app = wx.App() frame = testFrame(title="test") frame.Show() app.MainLoop()
The results are shown below:
This program does not achieve typing speed, but hand speed. Each time a character changes in a text input control, it counts as a valid operation, including adding or deleting characters. Count the number of keystrokes per second by dividing the number of character changes by time. When enter is struck, the count is cleared and the process starts again.
First look at the initialization function, defining self.count for counting, self.timeStart for recording the initial time, time module may be often used in some algorithm tests.
Then there is the multiline text input control, to which we bind two functions. onText is the response to the event when Enter is struck, in which case the count is reset to zero and the initial time is reassigned. onCount represents the number of operations per unit time in response to a change in content by dividing the count variable by the time difference.
Then define a scroll bar, minValue, maxValue these two parameters as the name implies, that is, the minimum value and maximum value. Style is style. We also mentioned it when defining the input text box before, but this time there is one more "style" in the definition.|"Character.
"|"character stands for or, if we want a control to have multiple styles at the same time, we can use"|"To connect. Wx.Slider's style is varied. The two styles we invoke represent:
wx.SL_VERTICAL indicates that we created a vertical slider. The default is landscape and its flag is wx.HORIZONTAL.
wx.SL_INVERSE indicates the direction in which we flip the maximum and minimum values.
Thank you for reading, the above is "python optical simulation learning wxpython how to create hand speed test program" content, after the study of this article, I believe that we have a deeper understanding of python optical simulation learning wxpython how to create hand speed test program, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.