I have a lottery program which is written by python(PYQT5). Now,I got the lucky number in the back first and roll the label. I want to paste the answer finally. Like code.
r_list = [0,1,2,3,4,5,6,7,8,9] #random list
animation(label,r_list,ans) #GUI showing
#GUI showing (label,random list,final text)
def animation(label,r_list,ans):
show_timmer = 5 #time of animation(sec)
#animation
timeline = QtCore.QTimeLine(show_timmer * 1000, self) #time of timeline
timeline.setFrameRange(label.geometry().top(), label.geometry().width()) #range of anumation
timeline.setLoopCount(1) #action times
timeline.frameChanged.connect(lambda: self.__set_frame_func(label,r_list)) #animation action
timeline.start() #anumation start
#finally:paste the answer
#anumation action:rolling label
def set_frame_func(label,r_list):
msg = r_list[random.randint(0,len(r_list)-1)] #random text
label.setText(msg) #change the text
return
Accroding to the code, I try in vain to finish the code.
#finally:paste the answer
while True:
if timeline.state() == 0:
label.setText(ans)
break
#finally:paste the answer
time.sleep(show_timmer)
label.setText(ans)
#finally:paste the answer
start = time.time()
while True:
if time.time() - start >= show_timmer:
break
label.setText(ans)
All the ways will crash the computer. Which case I can reference?
I'm poor at English. I'm sorry if I offend.
Related
I've created a program that is supposed to take the question and entry from a user and copy it to the clipboard. It works fine as a regular program but when I try to adapt it in trying to adapt it to a GUI I am running into an issue. Currently the program is only copying the question and the entries are returning empty strings. I know that if a broke down each entry into its own named variable I could probably fix this issue but a loop seems like a much cleaner solution. Can anyone assist?
import tkinter as tk
from tkinter import *
import pyperclip
system = 'What is the system?'
product = 'What is the product?'
issue = 'What is the issue?'
error = 'Is there an error message?'
screenshot = 'Do you have a screenshot or documentation for this issue?'
impact = 'Is the floor impacted. If so, what is the impact?'
users = 'How many users is this affecting?'
troubleshooting = 'Was there troubleshooting performed?'
changes = 'Are you aware of any changes that may have led up to the issue?'
ticket = 'Do you have an internal ticket number?'
questions = (
system, product, issue, error,
screenshot, impact, users, troubleshooting,
changes, ticket)
entries = []
clip = []
index = 0
index=0
c=0
r=0
root = tk.Tk()
root.title('SysIt4')
top_frame=tk.Frame(root)
bottom_frame=tk.Frame(root)
top_frame.grid(column=0, row=0, sticky=W)
bottom_frame.grid(column=0, row=1)
canvas = tk.Canvas(root, width=600, height=800)
canvas.grid()
while index < 10:
label = tk.Label(top_frame, text=questions[index])
label.grid(columnspan=2, column=c, row=r, sticky=W)
r+=2
index += 1
for r in range(1,20,2):
entry = tk.Entry(top_frame, width=50)
entry.grid(columnspan=2, column=c, row=r, sticky=W, padx=10, pady=5)
entries.append(entry)
def enact_clip(entries, questions):
responses = []
outfile= open('copy.txt', 'w')
for entry in entries:
responses.append(entry.get())
clip = list(zip(questions, responses))
for line in clip:
outfile.write(str(line) + '\n')
outfile.close()
infile = open('copy.txt', 'r')
copy_contents = infile.read()
return pyperclip.copy(copy_contents)
infile.close()
clip_button = Button(bottom_frame, text='Clip', command= enact_clip(entries, questions))
clip_button.grid(column=0, row=1)
root.mainloop()
I'm working with an algo on the bitstamp client that works better with 30-min bars, rather than seeing each trade as a bar.
Is there a "right" way to resample those bars into 30-min intervals on the fly?
I can do it no problem with the bitcoincharts broker, but I need the execution from the bitstampbroker, so I was hoping to do it with one.
This should help:
from pyalgotrade.bitstamp import barfeed
from pyalgotrade.bitstamp import broker
from pyalgotrade import strategy
class Strategy(strategy.BaseStrategy):
def __init__(self, feed, brk):
super(Strategy, self).__init__(feed, brk)
self._instrument = "BTC"
self._bid = None
self._ask = None
self._resampledBF = self.resampleBarFeed(60, self.onResampledBars)
# Subscribe to order book update events to get bid/ask prices to trade.
feed.getOrderBookUpdateEvent().subscribe(self._onOrderBookUpdate)
def _onOrderBookUpdate(self, orderBookUpdate):
bid = orderBookUpdate.getBidPrices()[0]
ask = orderBookUpdate.getAskPrices()[0]
if bid != self._bid or ask != self._ask:
self._bid = bid
self._ask = ask
self.info("Order book updated. Best bid: %s. Best ask: %s" % (self._bid, self._ask))
def onResampledBars(self, dt, bars):
bar = bars[self._instrument]
self.info("Resampled - Price: %s. Volume: %s." % (bar.getClose(), bar.getVolume()))
def onBars(self, bars):
bar = bars[self._instrument]
self.info("Price: %s. Volume: %s." % (bar.getClose(), bar.getVolume()))
def main():
barFeed = barfeed.LiveTradeFeed()
brk = broker.PaperTradingBroker(1000, barFeed)
strat = Strategy(barFeed, brk)
strat.run()
if __name__ == "__main__":
main()
I have made that loop my self and Iam trying to make it faster, better... but sometimes after it repeat searching for existing... it press random ( i think cuz its not similar to any img iam using in sikuli ) place on the screen. Maybe you will know why.
Part of this loop below
while surowiec_1:
if exists("1451060448708.png", 1) or exists("1451061746632.png", 1):
foo = [w_lewo, w_prawo, w_dol, w_gore]
randomListElement = foo[random.randint(0,len(foo)-1)]
click(randomListElement)
wait(3)
else:
if exists("1450930340868.png", 1 ):
click(hemp)
wait(1)
hemp = exists("1450930340868.png", 1)
elif exists("1451086210167.png", 1):
click(tree)
wait(1)
tree = exists("1451086210167.png", 1)
elif exists("1451022614047.png", 1 ):
hover("1451022614047.png")
click(flower)
flower = exists("1451022614047.png", 1)
elif exists("1451021823366.png", 1 ):
click(fish)
fish = exists("1451021823366.png")
elif exists("1451022083851.png", 1 ):
click(bigfish)
bigfish = exists("1451022083851.png", 1)
else:
foo = [w_lewo, w_prawo, w_dol, w_gore]
randomListElement = foo[random.randint(0,len(foo)-1)]
click(randomListElement)
wait(3)
I wonder if this is just program problem with img recognitions or I have made a mistake.
You call twice the exist method indending to get the same match (the first one in your if statement, the second time to assign it to the value. You ask sikuli to evaluate the image twice, and it can have different results.
From the method's documentation
the best match can be accessed using Region.getLastMatch() afterwards.
I read this topic because I forget a method I found in the net few month ago, and I don't know why I can't find it today, it was very simple and works good but...
So I tried one method but I think it doesn't work good or maybe my computer which is 5 years old is better than today's computer...
import time
debut=time.clock()
def t(n):
aaa=[]
b=n-1
c=0
if n==0 or n==1:
return 1
else:
while n != 1:
if n % 2==0:
n=n//2
aaa.append(n)
else:
n = n+b
aaa.append(n)
return [b,b+1]+aaa, len(aaa)+2
fin=time.clock()
print(t(100000),fin-debut)
For n=10.000.000 i can count in my head approx 5 secondes and computer always return 3.956927685067058e-06 ... can someone explain me ?
And the method I found, used this from time import perf_counter as pc
And I had to return print(pc()-t)
If someone can enlighten me because i really don't remember the method.
Thank you in advance
Look at the timeit module, https://docs.python.org/3.0/library/timeit.html.
you would set yours something like...
time = Timer( "t(100000)", "from __main__ import t")
print("time: ", timer.timeit(number=1000))
You are measuring the time it takes to define the function.
This will measure the execution of the function:
import time
def t(n):
aaa=[]
b=n-1
c=0
if n==0 or n==1:
return 1
else:
while n != 1:
if n % 2==0:
n=n//2
aaa.append(n)
else:
n = n+b
aaa.append(n)
return [b,b+1]+aaa, len(aaa)+2
start = time.time()
value = t(100000)
end = time.time()
duration = end - start
print(value, duration)
Short Version:
Program to:
control racing (cars) laptimes (it must not reset)
be able to use as a chronometer
b able to use as a reverse chronometer (start in X min:secs end in 00:00)
Long Version:
I need a program to control time, I need the time to go forth and back (for me to choose)
and I insert the starting time.
I also need a program to control lap times.
If anyone know any program for these stuff (racing stuff), I would apreciate it, even if there only are paid solution, I still would like to take a look at them (I staring to make a program in python and it could be good for inspiration)
After some search, I could only find this:
It's a simple clock in python TKinter..... if anyone has anything more advanced... (easier to change :) )
from Tkinter import *
import time
from Tkinter import *
import time
class StopWatch(Frame):
""" Implements a stop watch frame widget. """
def __init__(self, parent=None, **kw):
Frame.__init__(self, parent, kw)
self._start = 0.0
self._elapsedtime = 0.0
self._running = 0
self.timestr = StringVar()
self.makeWidgets()
def makeWidgets(self):
""" Make the time label. """
l = Label(self, textvariable=self.timestr)
self._setTime(self._elapsedtime)
l.pack(fill=X, expand=NO, pady=2, padx=2)
def _update(self):
""" Update the label with elapsed time. """
self._elapsedtime = time.time() - self._start
self._setTime(self._elapsedtime)
self._timer = self.after(50, self._update)
def _setTime(self, elap):
""" Set the time string to Minutes:Seconds:Hundreths """
minutes = int(elap/60)
seconds = int(elap - minutes*60.0)
hseconds = int((elap - minutes*60.0 - seconds)*100)
self.timestr.set('%02d:%02d:%02d' % (minutes, seconds, hseconds))
def Start(self):
""" Start the stopwatch, ignore if running. """
if not self._running:
self._start = time.time() - self._elapsedtime
self._update()
self._running = 1
def Stop(self):
""" Stop the stopwatch, ignore if stopped. """
if self._running:
self.after_cancel(self._timer)
self._elapsedtime = time.time() - self._start
self._setTime(self._elapsedtime)
self._running = 0
def Reset(self):
""" Reset the stopwatch. """
self._start = time.time()
self._elapsedtime = 0.0
self._setTime(self._elapsedtime)
def main():
root = Tk()
sw = StopWatch(root)
sw.pack(side=TOP)
Button(root, text='Start', command=sw.Start).pack(side=LEFT)
Button(root, text='Stop', command=sw.Stop).pack(side=LEFT)
Button(root, text='Reset', command=sw.Reset).pack(side=LEFT)
Button(root, text='Quit', command=root.quit).pack(side=LEFT)
root.mainloop()
if __name__ == '__main__':
main()
If you want to go with a packaged solution, you should try some of the apps:
for your android phone: http://www.bestandroidappsreview.com/2010/05/top-android-app-ultimate-stopwatch.html
for your iphone: http://www.apple.com/webapps/utilities/stopwatch_benku.html which is free, but if you want a more powerful stopwatch you should try LAPZERO app (see demo http://www.lapzero.com/v4/)
for your windows mobile phone: http://www.ageye.de/index.php?s=grace/about
or find one for your desktop computer platform/system on google
So what you want is a milliseconds accurate stop watch and lap timer.
Not that I have tried it but heres one I found on google http://www.xnotestopwatch.com/
I wish I could vote, cause that import tardis crack was a good one. :P