Skip to content

Commit 91da5ed

Browse files
Release 3.9.1 & 1.1.2
1 parent 8f7356f commit 91da5ed

23 files changed

Lines changed: 488 additions & 151 deletions

Demo_All_Widgets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
layout = [
2222
[sg.Menu(menu_def, tearoff=True)],
23-
[sg.Text('All graphic widgets in one form!', size=(30, 1), justification='center', font=("Helvetica", 25), relief=sg.RELIEF_RIDGE)],
23+
[sg.Text('All graphic widgets in one Window!', size=(30, 1), justification='center', font=("Helvetica", 25), relief=sg.RELIEF_RIDGE, text_color='midnightblue')],
2424
[sg.Text('Here is some text.... and a place to enter text')],
2525
[sg.InputText('This is my text')],
2626
[sg.Frame(layout=[

Demo_Button_States.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
layout = [[sg.T('User:', pad=((3,0),0)), sg.OptionMenu(values = ('User 1', 'User 2'), size=(20,1)), sg.T('0', size=(8,1))],
1717
[sg.T('Customer:', pad=((3,0),0)), sg.OptionMenu(values=('Customer 1', 'Customer 2'), size=(20,1)), sg.T('1', size=(8,1))],
1818
[sg.T('Notes:', pad=((3,0),0)), sg.In(size=(44,1), background_color='white', text_color='black')],
19-
[sg.ReadButton('Start', button_color=('white', 'black'), key='Start'),
20-
sg.ReadButton('Stop', button_color=('white', 'black'), key='Stop'),
21-
sg.ReadButton('Reset', button_color=('white', 'firebrick3'), key='Reset'),
22-
sg.ReadButton('Submit', button_color=('white', 'springgreen4'), key='Submit')]]
19+
[sg.ReadButton('Start', button_color=('white', 'black'), key='_Start_'),
20+
sg.ReadButton('Stop', button_color=('white', 'black'), key='_Stop_'),
21+
sg.ReadButton('Reset', button_color=('white', 'firebrick3'), key='_Reset_'),
22+
sg.ReadButton('Submit', button_color=('white', 'springgreen4'), key='_Submit_')]]
2323

2424
window = sg.Window("Time Tracker", default_element_size=(12,1), text_justification='r', auto_size_text=False, auto_size_buttons=False,
2525
default_button_element_size=(12,1)).Layout(layout).Finalize()
2626

2727

28-
for key, state in {'Start': False, 'Stop': True, 'Reset': True, 'Submit': True}.items():
28+
for key, state in {'_Start_': False, '_Stop_': True, '_Reset_': True, '_Submit_': True}.items():
2929
window.FindElement(key).Update(disabled=state)
3030

3131
recording = have_data = False
@@ -34,18 +34,18 @@
3434
print(button)
3535
if button is None:
3636
sys.exit(69)
37-
if button is 'Start':
38-
for key, state in {'Start':True, 'Stop':False, 'Reset':False, 'Submit':True}.items():
37+
if button == '_Start_':
38+
for key, state in {'_Start_':True, '_Stop_':False, '_Reset_':False, '_Submit_':True}.items():
3939
window.FindElement(key).Update(disabled=state)
4040
recording = True
41-
elif button is 'Stop' and recording:
42-
[window.FindElement(key).Update(disabled=value) for key,value in {'Start':False, 'Stop':True, 'Reset':False, 'Submit':False}.items()]
41+
elif button == '_Stop_' and recording:
42+
[window.FindElement(key).Update(disabled=value) for key,value in {'_Start_':False, '_Stop_':True, '_Reset_':False, '_Submit_':False}.items()]
4343
recording = False
4444
have_data = True
45-
elif button is 'Reset':
46-
[window.FindElement(key).Update(disabled=value) for key,value in {'Start':False, 'Stop':True, 'Reset':True, 'Submit':True}.items()]
45+
elif button == '_Reset_':
46+
[window.FindElement(key).Update(disabled=value) for key,value in {'_Start_':False, '_Stop_':True, '_Reset_':True, '_Submit_':True}.items()]
4747
recording = False
4848
have_data = False
49-
elif button is 'Submit' and have_data:
50-
[window.FindElement(key).Update(disabled=value) for key,value in {'Start':False, 'Stop':True, 'Reset':True, 'Submit':False}.items()]
49+
elif button is '_Submit_' and have_data:
50+
[window.FindElement(key).Update(disabled=value) for key,value in {'_Start_':False, '_Stop_':True, '_Reset_':True, '_Submit_':False}.items()]
5151
recording = False

Demo_Color_Names.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Shows a big chart of colors... give it a few seconds to create it
1212
Once large window is shown, you can click on any color and another window will popup
1313
showing both white and black text on that color
14+
Uses TOOLTIPS to show the hex values for the colors. Hover over a color and a tooltip will show you the RGB
1415
You will find the list of tkinter colors here:
1516
http://www.tcl.tk/man/tcl8.5/TkCmd/colors.htm
1617
@@ -670,7 +671,7 @@
670671
}
671672

672673

673-
sg.SetOptions(button_element_size=(12,1), element_padding=(0,0), auto_size_buttons=False, border_width=1)
674+
sg.SetOptions(button_element_size=(12,1), element_padding=(0,0), auto_size_buttons=False, border_width=1, tooltip_time=100)
674675

675676
layout = [[sg.Text('Hover mouse to see RGB value, click for white & black text', text_color='blue', font='Any 15', relief=sg.RELIEF_SUNKEN, justification='center', size=(100,1), background_color='light green', pad=(0,(0,20))),]]
676677
row = []
@@ -689,5 +690,5 @@
689690
if b is None:
690691
break
691692
# -- Create a secondary window that shows white and black text on chosen color
692-
layout2 =[[sg.Button(b, button_color=('white', b), tooltip=color_map[b]), sg.Button(b, button_color=('black', b), tooltip=color_map[b])] ]
693-
sg.Window('Buttons with white and black text', keep_on_top=True).Layout(layout2).Read()
693+
layout2 =[[sg.DummyButton(b, button_color=('white', b), tooltip=color_map[b]), sg.DummyButton(b, button_color=('black', b), tooltip=color_map[b])] ]
694+
sg.Window('Buttons with white and black text', keep_on_top=True).Layout(layout2).ReadNonBlocking()

Demo_Color_Names_Smaller_List.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,5 @@
109109
if b is None:
110110
break
111111
# -- Create a secondary window that shows white and black text on chosen color
112-
layout2 =[[sg.Button(b, button_color=('white', b)), sg.Button(b, button_color=('black', b))] ]
113-
sg.Window('Buttons with white and black text', keep_on_top=True).Layout(layout2).Read()
112+
layout2 =[[sg.DummyButton(b, button_color=('white', b)), sg.DummyButton(b, button_color=('black', b))] ]
113+
sg.Window('Buttons with white and black text', keep_on_top=True).Layout(layout2).ReadNonBlocking()

Demo_Cookbook_Browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def button2():
277277
break
278278

279279
# All done!
280-
sg.PopupOk('Done')
280+
sg.PopupOK('Done')
281281

282282
def RealtimeButtons():
283283
"""

Demo_Desktop_Widget_CPU_Utilization.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,16 @@ def main():
4545

4646
# ---------------- Create Form ----------------
4747
sg.ChangeLookAndFeel('Black')
48-
layout = [[sg.Text('', size=(8,1), font=('Helvetica', 20),text_color=sg.YELLOWS[0], justification='center', key='text')],
48+
layout = [[sg.Text('', size=(8,1), font=('Helvetica', 20),text_color=sg.YELLOWS[0],
49+
justification='center', key='text')],
4950
[sg.Text('', size=(30, 8), font=('Courier New', 12),text_color='white', justification='left', key='processes')],
50-
[sg.Exit(button_color=('white', 'firebrick4'), pad=((15,0), 0)), sg.Spin([x+1 for x in range(10)], 1, key='spin')],]
51+
[sg.Exit(button_color=('white', 'firebrick4'), pad=((15,0), 0), size=(9,1)),
52+
sg.Spin([x+1 for x in range(10)], 1, key='spin')],]
5153

52-
window = sg.Window('CPU Utilization', no_titlebar=True, auto_size_buttons=False,
53-
keep_on_top=True, grab_anywhere=True).Layout(layout)
54+
window = sg.Window('CPU Utilization',
55+
no_titlebar=True,
56+
keep_on_top=True,
57+
grab_anywhere=True).Layout(layout)
5458

5559
# start cpu measurement thread
5660
thread = Thread(target=CPU_thread,args=(None,))

Demo_Desktop_Widget_CPU_Utilization_Simple.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@
1010

1111
# ---------------- Create Form ----------------
1212
sg.ChangeLookAndFeel('Black')
13-
layout = [[sg.Text('')],
14-
[sg.Text('', size=(8, 2), font=('Helvetica', 20), justification='center', key='text')],
15-
[sg.Exit(button_color=('white', 'firebrick4'), pad=((15, 0), 0)),
16-
sg.Spin([x + 1 for x in range(10)], 1, key='spin')]]
17-
# Layout the rows of the form and perform a read. Indicate the form is non-blocking!
18-
window = sg.Window('CPU Meter', no_titlebar=True, auto_size_buttons=False, keep_on_top=True, grab_anywhere=True).Layout(layout)
13+
14+
layout = [[sg.Text('CPU Utilization')],
15+
[sg.Text('', size=(8, 2), font=('Helvetica', 20), justification='center', key='_text_')],
16+
[sg.Exit(button_color=('white', 'firebrick4'), pad=((15, 0), 0), size=(9,1)),
17+
sg.Spin([x + 1 for x in range(10)], 1, key='_spin_')]]
18+
19+
# Layout the rows of the Window
20+
window = sg.Window('CPU Meter',
21+
no_titlebar=True,
22+
keep_on_top=True,
23+
grab_anywhere=True).Layout(layout)
1924

2025
# ---------------- main loop ----------------
2126
while (True):
@@ -26,15 +31,15 @@
2631
if values is None or button == 'Exit':
2732
break
2833
try:
29-
interval = int(values['spin'])
34+
interval = int(values['_spin_'])
3035
except:
3136
interval = 1
3237

3338
cpu_percent = psutil.cpu_percent(interval=interval)
3439

3540
# --------- Display timer in window --------
3641

37-
window.FindElement('text').Update(f'CPU {cpu_percent:02.0f}%')
42+
window.FindElement('_text_').Update(f'CPU {cpu_percent:02.0f}%')
3843

3944
# Broke out of main loop. Close the window.
4045
window.CloseNonBlocking()

Demo_Desktop_Widget_Timer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
sg.ReadButton('Reset', button_color=('white', '#007339'), key='Reset'),
2424
sg.Exit(button_color=('white', 'firebrick4'), key='Exit')]]
2525

26-
window = sg.Window('Running Timer', no_titlebar=False, auto_size_buttons=False, keep_on_top=True, grab_anywhere=True).Layout(layout)
26+
window = sg.Window('Running Timer', no_titlebar=True, auto_size_buttons=False, keep_on_top=True, grab_anywhere=True).Layout(layout)
2727

2828
# ---------------- main loop ----------------
2929
current_time = 0

Demo_Graph_Drawing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
window = sg.Window('Graph test').Layout(layout).Finalize()
1212

1313
graph = window.FindElement('graph')
14-
circle = graph.DrawCircle((75,75), 25, fill_color='black',line_color='white')
14+
circle =graph .DrawCircle((75,75), 25, fill_color='black',line_color='white')
1515
point = graph.DrawPoint((75,75), 10, color='green')
1616
oval = graph.DrawOval((25,300), (100,280), fill_color='purple', line_color='purple' )
1717
rectangle = graph.DrawRectangle((25,300), (100,280), line_color='purple' )

Demo_Img_Viewer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
Python v3
2323
PIL
2424
"""
25-
# Get the folder containing the images from the user
26-
rc, folder = sg.GetPathBox('Image Browser', 'Image folder to open', default_path='')
27-
if not rc or not folder:
25+
# Get the folder containin:g the images from the user
26+
folder = sg.PopupGetFolder('Image folder to open', default_path='')
27+
if not folder:
2828
sg.PopupCancel('Cancelling')
2929
raise SystemExit()
3030

@@ -89,7 +89,7 @@ def get_img_data(f, maxsize = (1200, 850), first = False):
8989
while True:
9090
# read the form
9191
button, values = window.Read()
92-
92+
print(button, values)
9393
# perform button and keyboard operations
9494
if button is None:
9595
break
@@ -103,7 +103,7 @@ def get_img_data(f, maxsize = (1200, 850), first = False):
103103
if i < 0:
104104
i = num_files + i
105105
filename = os.path.join(folder, fnames[i])
106-
elif button in ('Read', ''): # something from the listbox
106+
elif button == 'listbox': # something from the listbox
107107
f = values["listbox"][0] # selected filename
108108
filename = os.path.join(folder, f) # read this file
109109
i = fnames.index(f) # update running index

0 commit comments

Comments
 (0)