Pysimplegui: my status bar is acting strange

Created on 29 Jun 2020  路  11Comments  路  Source: PySimpleGUI/PySimpleGUI

Type of Issues ( Bug, Question)

the status bar isn't doing what i expected it would

Operating System

windows 10

Python version

Python 3.8.3

PySimpleGUI Port and Version

PySimpleGUI 4.20.0

Your Experience Levels In Months or Years

1m\2m_______ Python programming experience
1m\2m_______ Programming experience overall
tkinter_____Have used another Python GUI Framework (tkinter, Qt, etc) previously (yes/no is fine)?

You have completed these steps:

  • [ n] Read instructions on how to file an Issue
  • [ y] Searched through main docs http://www.PySimpleGUI.org for your problem
  • [? ] Searched through the readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
  • [y ] Looked for Demo Programs that are similar to your goal http://www.PySimpleGUI.com
  • [ ] Note that there are also Demo Programs under each port on GitHub
  • [y ] Run your program outside of your debugger (from a command line)
  • [y ] Searched through Issues (open and closed) to see if already reported
  • [n ] Try again by upgrading your PySimpleGUI.py file to use the current one on GitHub. Your problem may have already been fixed but is not yet on PyPI.

Description of Problem / Question / Details

original post on stackoverflow
my problem:

i have been trying to make a python clone of notepad to learn how pysimplegui works. so i started with following this video and then changed some code around to look more like notepad. but when i added a status bar i noticed it did not act the way i wanted instead of it being a small strip at the bottom of the window it has a big border going under it and when i resize the window the status bar doesn't really move vertically.

code and images:

here is the code for the gui:

this is a image of my notepad clone

looks fine right?

well this is what it look like when streched

this is Microsofts notepad when maximized

and this is my clone when maximized

what i tried:

1 I added pad(0,0) to the status bar element

2 I adding expand_row=True to the .expand line of code but noticed no difference

3 I tried to change the size of the element

4 I tried to google for an answer

5 I looked at the pysimplegui docs website

Most helpful comment

PySimpleGUI was originally designed with a much more static kind of layout definition than it has today. Over time it's been expanded to be a bit more dynamic. Methods like expand were added.

Sometimes you may run into a situation where you need direct access to the underlying tkinter Widget. Capabilities are there for you to do so. In short, it's possible, but it's tricky.

The "StatusBar" element was a quick addition to the tkinter port of PySimpleGUI and is in reality a Text Element. It was done in reaction to the fact the Qt has a separate StatusBar widget.

Anyway, to get the effect you're after, try this code:

#~~~~imports~~~~
import PySimpleGUI as sg

WIN_W = 90
WIN_H = 25

'''
sg.ChangeLookAndFeel('SystemDefault')
'''
#~~~~layout~~~~
#/settings
menu_def = [['File', ['New    Ctrl+N', 'Open...    Ctrl+O', 'Save    Ctrl+S','Save As...', '---', 'Page Setup...', 'Print...    Ctrl+P', '---', 'Exit'  ]],      
                ['Edit', ['Undo    Ctrl+Z', '---', 'cut    Ctrl+X', 'copy    Ctrl+C', 'Paste    Ctrl+V', 'delete    Del', '---', 'find...    Ctrl+F', 'Find Next    F3', 'Replace...    Ctrl+H', 'Go To...    Ctrl+G', '---', 'Select All    Ctrl+A', 'Time/Date    F5'], ],
                ['format', ['Word Wrap', 'font...'], ],
                ['view', ['Status Bar'], ],      
                ['Help', ['View Help', '---', 'About memopad'], ], ]

Ln_numb = 1
Col_numb = 1
#/the layout
layout = [[sg.Menu(menu_def)],
          [sg.Multiline(font=('Consolas', 12), size=(WIN_W, WIN_H-1), key='_BODY_')],
          [sg.StatusBar( text=f'| Ln{Ln_numb},Col{Col_numb}', size=(WIN_W,1), pad=(0,0), text_color='black', background_color='white', relief=sg.RELIEF_FLAT, justification='right', visible=True, key='status_bar' )]
          ]

#/window
window = sg.Window('untitled - notepad', icon=['D:/python/memopad/Notepad.ICO'], border_depth=0, layout=layout, element_padding=(0, 0), margins=(0, 0), resizable=True, return_keyboard_events=True, finalize=True)

window['status_bar'].ParentRowFrame.pack(fill='x')
window['_BODY_'].expand(expand_x=True, expand_y=True)

status_bar_switch = False
while True:
    event, values = window.read()
    if event in (None, 'Exit'):
        break

    if event == 'Status Bar':
        if status_bar_switch:
            window['status_bar'].ParentRowFrame.pack(fill='x')
            window['status_bar'].update(visible=True)
            window['status_bar'].Widget.pack(fill='x')
            status_bar_switch = False
        else:
            window['status_bar'].update(visible=False)
            window['status_bar'].ParentRowFrame.pack_forget()
            status_bar_switch = True

A big THANK YOU is owed to @israel-dryer for his help in not only writing the notepad demo, but making the youtube video and helping out with this problem!

All 11 comments

Can you please fill in the form so I know what OS you're running on, etc?

Can you please fill in the form so I know what OS you're running on, etc?

sorry to ask but im new how do i fill out the form

Click the green button when you click on New Issue:

image

Click the green button when you click on New Issue:

image

so i have to post i new issue?

You can edit your initial post to include the text. Start a new issue and copy over the blank parts.

alright did it

Excellent.... working on it.... more shortly. Thanks for filling it all in.

PySimpleGUI was originally designed with a much more static kind of layout definition than it has today. Over time it's been expanded to be a bit more dynamic. Methods like expand were added.

Sometimes you may run into a situation where you need direct access to the underlying tkinter Widget. Capabilities are there for you to do so. In short, it's possible, but it's tricky.

The "StatusBar" element was a quick addition to the tkinter port of PySimpleGUI and is in reality a Text Element. It was done in reaction to the fact the Qt has a separate StatusBar widget.

Anyway, to get the effect you're after, try this code:

#~~~~imports~~~~
import PySimpleGUI as sg

WIN_W = 90
WIN_H = 25

'''
sg.ChangeLookAndFeel('SystemDefault')
'''
#~~~~layout~~~~
#/settings
menu_def = [['File', ['New    Ctrl+N', 'Open...    Ctrl+O', 'Save    Ctrl+S','Save As...', '---', 'Page Setup...', 'Print...    Ctrl+P', '---', 'Exit'  ]],      
                ['Edit', ['Undo    Ctrl+Z', '---', 'cut    Ctrl+X', 'copy    Ctrl+C', 'Paste    Ctrl+V', 'delete    Del', '---', 'find...    Ctrl+F', 'Find Next    F3', 'Replace...    Ctrl+H', 'Go To...    Ctrl+G', '---', 'Select All    Ctrl+A', 'Time/Date    F5'], ],
                ['format', ['Word Wrap', 'font...'], ],
                ['view', ['Status Bar'], ],      
                ['Help', ['View Help', '---', 'About memopad'], ], ]

Ln_numb = 1
Col_numb = 1
#/the layout
layout = [[sg.Menu(menu_def)],
          [sg.Multiline(font=('Consolas', 12), size=(WIN_W, WIN_H-1), key='_BODY_')],
          [sg.StatusBar( text=f'| Ln{Ln_numb},Col{Col_numb}', size=(WIN_W,1), pad=(0,0), text_color='black', background_color='white', relief=sg.RELIEF_FLAT, justification='right', visible=True, key='status_bar' )]
          ]

#/window
window = sg.Window('untitled - notepad', icon=['D:/python/memopad/Notepad.ICO'], border_depth=0, layout=layout, element_padding=(0, 0), margins=(0, 0), resizable=True, return_keyboard_events=True, finalize=True)

window['status_bar'].ParentRowFrame.pack(fill='x')
window['_BODY_'].expand(expand_x=True, expand_y=True)

status_bar_switch = False
while True:
    event, values = window.read()
    if event in (None, 'Exit'):
        break

    if event == 'Status Bar':
        if status_bar_switch:
            window['status_bar'].ParentRowFrame.pack(fill='x')
            window['status_bar'].update(visible=True)
            window['status_bar'].Widget.pack(fill='x')
            status_bar_switch = False
        else:
            window['status_bar'].update(visible=False)
            window['status_bar'].ParentRowFrame.pack_forget()
            status_bar_switch = True

A big THANK YOU is owed to @israel-dryer for his help in not only writing the notepad demo, but making the youtube video and helping out with this problem!

alright thank you this really helps ill try out the code and post a comment if it works

yes it works thanks again not just for solving the issue but also for making such a beginner friendly gui system

You're quite welcome on all fronts!

Sorry you picked a weird thing to try and add on your first shot. They're not all this ugly looking, honest.

Dynamic layouts and stuff are difficult in PySimpleGUI generally speaking, but it's getting a bit better.

Come back again when you need help.

Was this page helpful?
0 / 5 - 0 ratings