File tree 4 files changed +127
-0
lines changed
__BIND__/escape-close-window
progressbar/progressbar-multiprocessing-process-queue
text/disabled-insert-text
4 files changed +127
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python3
2
+
3
+ # date: 2020.01.02
4
+ # ???
5
+
6
+
7
+ import tkinter as tk
8
+
9
+ # --- functions ---
10
+
11
+ def stop (event ):
12
+ root .destroy ()
13
+
14
+ # --- main ---
15
+
16
+ root = tk .Tk ()
17
+
18
+ root .bind ('<Escape>' , stop )
19
+ root .focus ()
20
+
21
+ root .mainloop ()
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python3
2
+
3
+ # date: 2019.12.22
4
+ #https://stackoverflow.com/questions/59441994/how-to-generate-tab-key-even-when-enter-key-pressed-in-tkinter-python
5
+
6
+
7
+
8
+ import tkinter as tk
9
+
10
+ root = tk .Tk ()
11
+
12
+ e1 = tk .Entry (root )
13
+ e1 .pack ()
14
+ e2 = tk .Entry (root )
15
+ e2 .pack ()
16
+ print (e1 )
17
+ #root.call('bind .!entry <Return> {event generate %W <Tab>}')
18
+ #bind .w <Return> {event generate %W <Tab>}
19
+ e1 .bind ('<Return>' , 'event generate %W <Tab>' )
20
+ #e2.bind('<Return>', 'event generate %W <Tab>')
21
+ #e2.bind('<Return>', lambda x:root.event_generate('<Tab>'))
22
+ #e2.bind('<Return>', '<Tab>')
23
+ e2 .bind ('<Return>' , root .bind_all ("<Tab>" )) # doesn't work on Linux ?
24
+
25
+ root .mainloop ()
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python3
2
+
3
+ # date: 2019.12.21
4
+ #
5
+
6
+ import multiprocessing
7
+ import time
8
+ import tkinter .ttk as ttk
9
+ #from tkinter import * # not preferred
10
+ import tkinter as tk
11
+
12
+ class SubWindow :
13
+
14
+ def __init__ (self , master ):
15
+ self .master = master
16
+
17
+ self .win = tk .Toplevel (master )
18
+ #self.win.wm_attributes('-topmost', 1)
19
+
20
+ l = tk .Label (self .win , text = 'Please, wait...' )
21
+ l .pack ()
22
+
23
+ self .pb = ttk .Progressbar (self .win , mode = "determinate" )
24
+ self .pb .pack ()
25
+
26
+ self .queue = multiprocessing .Queue ()
27
+
28
+ self .p = multiprocessing .Process (target = self .process , args = (self .queue ,))
29
+ self .p .start ()
30
+ #p.join() # don't use in this place becaus it blocks all code
31
+
32
+ self .update_progressbar ()
33
+
34
+ def update_progressbar (self ):
35
+ if not self .queue .empty ():
36
+ self .pb ['value' ] += self .queue .get ()
37
+
38
+ if self .pb ['value' ] < 100 :
39
+ self .win .after (100 , self .update_progressbar )
40
+ else :
41
+ self .p .join ()
42
+ self .win .destroy ()
43
+
44
+ def process (self , queue ):
45
+ for i in range (10 ):
46
+ print ('loop:' , i )
47
+ queue .put (10 )
48
+ time .sleep (.5 )
49
+
50
+
51
+ if __name__ == "__main__" :
52
+ root = tk .Tk ()
53
+ tk .Button (root , text = 'Start processing!' , command = lambda :SubWindow (root )).pack (side = 'top' )
54
+ root .mainloop ()
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python3
2
+
3
+ # date: 2020.01.02
4
+ # ???
5
+
6
+ import tkinter as tk
7
+ import tkinter .scrolledtext as st
8
+ import datetime
9
+
10
+ # --- functions ---
11
+
12
+ def on_click ():
13
+ text ['state' ] = 'normal'
14
+ text .insert ('end' , str (datetime .datetime .now ()) + '\n ' )
15
+ text ['state' ] = 'disabled'
16
+
17
+ # --- main ---
18
+
19
+ root = tk .Tk ()
20
+
21
+ text = st .ScrolledText (root , state = 'disabled' )
22
+ text .pack ()
23
+
24
+ button = tk .Button (root , text = 'ADD' , command = on_click )
25
+ button .pack ()
26
+
27
+ root .mainloop ()
You can’t perform that action at this time.
0 commit comments