Updating data from Bitcoin exchange API in Tkinter using Python -



Updating data from Bitcoin exchange API in Tkinter using Python -

i wrote little programme using tkinter print out cost of bitcoin different exchange api. want able update info each x seconds can't figure out how. guess i'll need utilize .after( delay_ms, callback, args ) method.

am right?

# python 2.7.6. calling exchange apis. import time, json, requests tkinter import * root = tk() def bitstampusd(): bitstampusdtick = requests.get( 'https://www.bitstamp.net/api/ticker/' ) homecoming bitstampusdtick.json()['last'] def btceusd(): btcebtctick = requests.get( 'https://btc-e.com/api/2/btc_usd/ticker' ) homecoming btcebtctick.json()['ticker']['last'] bitstampusdlive = float( bitstampusd() ) btceusdlive = float( btceusd() ) photo = photoimage( file = './images/blackcoin_500_small.gif' ) text1 = text( root, height = 30, width = 31 ) text1.insert( end,'\n' ) text1.image_create( end, image = photo ) text1.pack( side = left ) text2 = text( root, height = 30, width = 60 ) scroll = scrollbar( root, command = text2.yview ) text2.configure( yscrollcommand = scroll.set ) text2.tag_configure( 'bold_italics', font = ( 'arial', 12, 'bold', 'italic' ) ) text2.tag_configure( 'bold', font = ( 'arial', 12, 'bold' ) ) text2.tag_configure( 'big', font = ( 'verdana', 20, 'bold' ) ) text2.tag_configure( 'medium', font = ( 'verdana', 14, 'bold' ) ) text2.tag_configure( 'color', font = ( 'tempus sans itc', 12, 'bold' ), foreground = '#476042' ) text2.tag_bind( 'follow', '<1>', lambda e, t = text2: t.insert( end, "not now, maybe later!" ) ) text2.insert( end, '\ncrypto cost ticker\n', 'big' ) text2.insert( end, "\nbitcoin exchange rates\n", "medium" ) text2.insert( end, "%.2f" % bitstampusdlive ) text2.insert( end, " usd - bitstamp\n" ) text2.insert( end, "%.2f" % btceusdlive ) text2.insert( end, " usd - btc-e\n" ) text2.pack( side = left ) scroll.pack( side = right, fill = y ) root.mainloop()

yes, tkinter .after() method ( may ) help, carefull...

tkinter has powerfull internal event-based & time-based scheduling service.

due care ought taken 1 time designing time-based , chained-scheduling scenarios mixed gui + non-gui activities. case, ill-chained request and/or poor scheduling logic may destroy/hang tkinter .mainloop() scheduler.

some prior experience near-real-time scheme designs help lot accomplish both responsive gui-part , "well-oiled" / error-handled non-gui-part, not de-stabilise both tkinter .mainloop() , remote-data api providers' interfaces.

.after( wms, task, *args ) # non-gui, pure mvc-controller time-based task scheduling .after_idle( task, *args ) # of import method defer task mvc-idle-<state> .after_cancel( ataskid ) # of import method release scheduled task .update_idletasks() # of import method enforce process task(s) ( if ) deferred idle-tasks-queue before next mvc-idle-<state> going step behind question "am right?"

using tkinter both gui layer services , it's timing ( scheduling ) services quite mutual practice.

your principal design shall separate sub-tasks in event-driven mode of command ( 1 time come in .mainloop() resort still remain in command of non-gui "background" activities ).

as redesign process command of processing in disjunct "layers" ( 1 of def-ed background bitcoin exchange api dialogue ) need provide means & controls updates pure gui-part of code ( via .stringvar(), intvar(), .booleanvar(), .doublevar() , associated triggering .trace_variable() tools ).

for sending non-gui asynchronous event code-driven tkinter stimulus, there powerfull method of .event_generate( <eventnameid>, **args ).

another sign of real-time design shall cut down traffic. state-full design will, trivial example, avoid gui re-paints in cases, no alter or identical value(s) retrieved external data-source or produced internal processing.

ask synchronous refresh or process stream of quotes?

there chance schedule phone call synchronous refresh of bitcoin exchange api-provided value. not problem in case of loose-timing design. going faster start create new problems. technical ( fair-queue scheduling, transport latencies, response end-to-end latencies ) , non-technical.

for processing of remote quote-streams or quote-publishing api(s), 1 may bear in mind official terms & conditions applicable data-access. api have server-side rate-limit controls, not, silently drop sessions, set on black-list violation of said terms & conditions.

using stream of quotes processing, offered exchange, may avoid falling in conflicts terms & conditions, upon growing refresh-rates and/or tighter-timing, each of mutual trap if not handled due care in design phase.

python api tkinter auto-update

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -