@@ -37,13 +37,13 @@ It's not easy to understand.
3737If you use ` asynctkinter ` , the code above will become:
3838
3939``` python
40- import asynctkinter as at
40+ import asynctkinter as atk
4141
4242async def what_you_want_to_do (clock , label ):
4343 print (' A' )
4444 await clock.sleep(1 )
4545 print (' B' )
46- await at .event(label, ' <Button>' )
46+ await atk .event(label, ' <Button>' )
4747 print (' C' )
4848
4949nursery.start(what_you_want_to_do(... ))
@@ -62,25 +62,25 @@ pip install "asynctkinter>=0.4,<0.5"
6262
6363``` python
6464import tkinter as tk
65- import asynctkinter as at
65+ import asynctkinter as atk
6666
6767
68- async def main (* , clock : at .Clock, root : tk.Tk):
68+ async def main (* , clock : atk .Clock, root : tk.Tk):
6969 label = tk.Label(root, text = ' Hello' , font = (' ' , 80 ))
7070 label.pack()
7171
7272 # waits for 2 seconds to elapse
7373 await clock.sleep(2 )
7474
7575 # waits for a label to be pressed
76- event = await at .event(label, ' <Button>' )
76+ event = await atk .event(label, ' <Button>' )
7777 print (f " pos: { event.x} , { event.y} " )
7878
7979 # waits for either 5 seconds to elapse or a label to be pressed.
8080 # i.e. waits at most 5 seconds for a label to be pressed
81- tasks = await at .wait_any(
81+ tasks = await atk .wait_any(
8282 clock.sleep(5 ),
83- at .event(label, ' <Button>' ),
83+ atk .event(label, ' <Button>' ),
8484 )
8585 if tasks[0 ].finished:
8686 print (" Timeout" )
@@ -90,21 +90,21 @@ async def main(*, clock: at.Clock, root: tk.Tk):
9090
9191 # same as the above
9292 async with clock.move_on_after(5 ) as timeout_tracker:
93- event = await at .event(label, ' <Button>' )
93+ event = await atk .event(label, ' <Button>' )
9494 print (f " The label got pressed. (pos: { event.x} , { event.y} ) " )
9595 if timeout_tracker.finished:
9696 print (" Timeout" )
9797
9898 # waits for both 5 seconds to elapse and a label to be pressed.
99- tasks = await at .wait_all(
99+ tasks = await atk .wait_all(
100100 clock.sleep(5 ),
101- at .event(label, ' <Button>' ),
101+ atk .event(label, ' <Button>' ),
102102 )
103103
104104 # nests as you want.
105105 tasks = await ak.wait_all(
106- at .event(label, ' <Button>' ),
107- at .wait_any(
106+ atk .event(label, ' <Button>' ),
107+ atk .wait_any(
108108 clock.sleep(5 ),
109109 ... ,
110110 ),
@@ -113,7 +113,7 @@ async def main(*, clock: at.Clock, root: tk.Tk):
113113
114114
115115if __name__ == " __main__" :
116- at .run(main)
116+ atk .run(main)
117117```
118118
119119### threading
@@ -123,11 +123,11 @@ thus threads may be the best way to perform them without blocking the main threa
123123
124124``` python
125125from concurrent.futures import ThreadPoolExecuter
126- import asynctkinter as at
126+ import asynctkinter as atk
127127
128128executer = ThreadPoolExecuter()
129129
130- async def async_fn (clock : at .Clock):
130+ async def async_fn (clock : atk .Clock):
131131 # create a new thread, run a function inside it, then
132132 # wait for the completion of that thread
133133 r = await clock.run_in_thread(thread_blocking_operation, polling_interval = 1.0 )
@@ -144,9 +144,9 @@ so you can catch them like you do in synchronous code:
144144
145145``` python
146146import requests
147- import asynctkinter as at
147+ import asynctkinter as atk
148148
149- async def async_fn (clock : at .Clock):
149+ async def async_fn (clock : atk .Clock):
150150 try :
151151 r = await clock.run_in_thread(lambda : requests.get(' htt...' , timeout = 10 ), ... )
152152 except requests.Timeout:
0 commit comments