New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inconsistent elements spacing between windows and linux #1654
Comments
Very nice looking windows you've made! It looks like the specific problem in the layout that goes too far to the right is the progress bars. They are pushing the right side of the Frame over and that in turn is making the window wider. The root problem you're facing is the difference in sizes between Linux Characters and Windows Characters. Perhaps changing the progress bar will be all you need to line it all up again, at least to some extent. The default sizing for PySimpleGUI (tkinter) is character based. In the other ports, like PySimpleGUIQt, this is remedied by a new parameter for the Element, You may want to start by changing your font to a specific set rather than Any. Helvetica is a good one generally speaking. As far as spacers go, there is a Stretch Element that's available in Qt, but nothing like it is available in tkinter, at least not in the way that layouts are done in PySimpleGUI at the moment. |
You can visibly see the difference in character sizes by looking at the heading alone. In the Linux screenshot, the characters take up 335 pixels. In the Windows version they span 310 pixels. |
Thanks a lot for your reply, your suggestion of using a specific font solved the problem for me, and now the window frame looks fine on both windows and linux
a great thanks, this is encouraging :) |
Can you post a couple of screenshots again showing it working correctly? Glad you're finding this experience "encouraging". You've arrived at the project at a good time because the documentation is being updated extensively. All of the Elements have docstrings and I'm adding them into the readme in a more consistent manner. It also means the readme will be up to date more often as it's getting easier and easier to generate a new readme. I'm hoping to be DONE with the primary Readme by end of the week. You can also use the Python help function as well as your IDE's capabilities. PyCharm does some magical things with doc strings. |
I'm surprised you are not able to simply used a fixed width text field that you center the text within and then have your button right after that. As it is, the Text Field is being "Autosized". I think it would work out a lot better to use a fixed size Text field. I assume you've got a lot of stuff happening inside your event loop than what you've shown here. If not, then there's no reason to have a timeout value on your read which will save you boatloads of CPU time. |
i think there was no option for center the text "my bad", i just changed this row to: [sg.Text('Hanash Download Manager', font='Helvetica 20', size=(37, 1), justification='center'),
sg.Button('', image_filename=r'icons/info025.png', size=(25, 25), key='about')] it looks better with less code :)
this application has a lot of threads running in background, it can download multiple files simultaneously with multi-connections / thread for each target file, and each download has its own gui window showing progress info, so sometimes i have 10 small windows running beside the main window, i have to admit, at first i didn't expect that PySimpleGUI design concept will work with a lot of concurrent windows but i am surprised how all theses windows are responsive with no lag with realtime data update. |
Multiple windows are no problem at all as you see :-) It baffles me, it truly does baffle me, as to why not one of the GUI vendors offers a secondary kind of interface to their objects.... one that looks like PySimpleGUI and is meant to fill this void. It's clear to me there's a void and it's sizable. Why can't tkinter at least do that? Make something that's usable by first week or first month Python students. Unfortunately there are a few trolls that like to get the word out as to how "horrified" PySimpleGUI is and that it is only good for overly simplistic problems. The last one was it was great at doing 2 "Labels" in a window but nothing more than that. This architecture has a lot to offer as you're learning. It's not difficult to write a multi-windowed application using PySimpleGUI. You just add more stuff to your event loop is all Sorry, I digress..... |
And I do like your quote, or soon to be a quote, "now gui works for me not the other way around." That's a great way of putting it. If I WANT to call a function when this button is clicked, I WILL, but maybe I just want to print a bit of text out instead. Or maybe I don't want to have to coordinate between 6 different functions that represent 6 different buttons that need to somehow communicate among themselves. You're forced into an object model more because they create virtual global variables than because they do a fantastic job of representing something, which they don't. Right? If you want these functions to share data, well, that data has to be either global data, which is a pain in the ass, or something else like them, which is what a class is. After all a class is a bunch of functions (methods) that access shared data (properties). Contrast all that with a single interface through which EVERYTHING flows. How simple to deal with. If I want a class, well, great, I can create a class, but I'm not forced to and in fact, it often feels forced if you try to implement too much OO on top of PySimpleGUI. I do sometimes implement stuff as a class, like the debugger. It's more for making it into a single entity that I'm doing it that way. I'm not a big OO fan, clearly. It's because my roots go well before that OO thing happened. I want to see more of your app as you develop it further!! It's a really advanced looking interface in my opinion. You're getting the most from it. I'm pleasantly surprised that the Linux and Windows versions weren't too far apart. Now if only the Qt and tkinter versions were closer. Is this a general purpose downloader you're making??? I could see this thing being very popular. Unfortunately drag and drop doesn't work in tkinter, but it does in Qt in case you wanted to try that some day. |
for me programming is a hobby, so you will find my code a lot of mess with a mix of functions and classes works together to get the job done whichever simpler and easier
yes, it downloads files from internet using pycurl a wrapper a round famous curl, and it can download youtube videos with all available qualities or download a youtube playlist at once
Thanks a lot, |
uploading to github was just drag and drop, |
Lookin good! A note on It does not do anything to a window that already exists. It does not do anything to a layout that already exists. If you want a certain look and feel to be applied to a window, you need to set the Look and Feel prior to to the All it does is set a bunch of default values. That's it. Changes default values so that when you create something, like a button, it'll use the new default values to create that button or the background or an element. |
yes i understand, i already restart the window creation once a new theme selected from combo box if event == 'themes':
theme = values['themes']
sg.ChangeLookAndFeel(theme)
restart_window() # a func to close window and recreate the layout and finalize() window |
OK, just wanted to make sure you understood why there are generally at the very beginning of the program. You have to call them before defining your layout, creating a window, even calling a popup. |
@MikeTheWatchGuy some other snapshots of different design tabs of the application |
DAMN!!!!! These are AWESOME shots. You did this stuff using straight PySimpleGUI calls? You didn't use tkinter directly? Are you going to make this available publicly? You did some really clever things, little tweaks, that had a big impact in the end. I like the progress meters and stats on one tab of a window. I'm not sure what's on the other. You're the first person I've seen use the status bar element at the bottom of the window. You've the first person I've seen offer the user the ability to change color schemes. It's pretty amazing looking coming from a single program. One thing I noticed was the lack of a MenuBar. It's what I was looking for to find the "main window" of the program. The MenuBar also lends credibly as you "look like" a "real" Windows program that way. I think it really helped the guy that built the chess game look like a Windows app: After I told him about right-click menus, he went crazy and was able to get rid of a bunch of buttons and instead turn them into right clickable items. Can you take a couple shots of just your download window and its two tabs (the one with main and log)? When / if you do release it, I highly suggest packing your readme full of screenshots. They look fantastic. I can't wait to get it and start using it!! Oh, and you're the first person that I've seen look at doing bother Windows and Linux ports simultaneously. |
wow! thanks a lot for your kind words
yes the whole design is a pure PySimpleGUI, i never tried using tkinter before and i don't know how to use it, my previous designs made by wxpython and pyqt5.
really thanks to you you made it available, a ready made themes, which in my opinion one of the greatest things PySimpleGUI is offering. regarding a menu bar and right click option i will try it
is this what you mean?
i took your advice and put the screenshots in readme file, it do look better with screenshots :) |
I ran into a similar issue, but the inconsistency is between two windows PCs and involves the slider. While it may be difficult to compare with pixels due to resolution differences, the laptop slider is clearly shorter than the desktop slider. On a somewhat related note, are there any monospaced fonts available for use in PySimpleGUI? Operating System: Windows 10 64-bit import PySimpleGUI as pSG
pSG.SetOptions(font=("Helvetica", 10))
layout = [
[pSG.Text("=" * 162)],
[pSG.Slider(range=(0, 1000), default_value=0, size=(100, 15), orientation="h")]
]
window = pSG.Window("test", layout)
window.Finalize()
while True:
event, values = window.Read() |
Yes, Courier New is the obvious choice, but there are others. There is a font viewer demo application that will show you. Or..... Google tkinter font names |
Thanks for letting me know. I never used tkinter before, so I'm pretty unfamilar with its features. I just re-tested that code with the slider on my laptop, it's output is now identical to the output on my desktop. I don't think I changed anything, so I'm not sure why the output would have changed. Also I'm not sure if this is intentional or not, but I just noticed that the font set with import PySimpleGUI as pSG
pSG.SetOptions(font=("Courier New", 20))
size = 50
layout = [
[pSG.Text("Testing")],
[pSG.Graph((size, size), (0, 0), (size, size), key="graph")]
]
window = pSG.Window("test", layout)
window.Finalize().Element("graph").DrawText("testing", (25, 25))
while True:
event, values = window.Read() |
The reason they're not the same is that SetOptions sets options for the Elements and Windows. The Graph element uses a DrawText method/primitive that has a different font set (subset) of the fonts available for elements. That's my understanding at least. |
You likely changed to using a fixed with font if they work together now. It would be great to get a screenshot. |
OK, so I guess the best way to set fonts for both graphs and non-graph elements would be to do something like this? myfont = ("Courier New", 20)
pSG.SetOptions(font=myfont)
...
graph.DrawText("testing", (25, 25), font=myfont) |
As I said before, I'm not sure about the font lists being the same for both the DrawText and normal window. I suggest looking at the tkinter docs about this. The tkinter call is As I mentioned in the docs, I don't recommend virtual environments as well as running on the bleeding edge of everything (Python 3.7.latest, latest matplotlib, etc). Keep it simple. Run 3.6 unless you have a specific purpose for 3.7. Do you close your window when you exit? There are HUGE WARNINGS all over the docs, the cookbook and in every single demo program about "giving your user a way to exit your program". If this is your event loop, how is it ever going to stop? while True:
event, values = window.Read() Where does your program "exit". READ THE DOCS, Follow the patterns. Don't skip by not wanting to type in code. There's a reason for pretty much everything. If you don't understand it, read the docs again. If after checking in all 3 places and still don't understand, then post here :-) |
Sorry, I should give the documentation a more thorough read. Having everything on single page is a bit intimidating so I've only skimmed through it so far. In regards to virtual environments, I only recently made the switch to using pipenv. Previously, I had used pip as though it were apt, installing everything to the system environment. If I needed a package I simply did I can understand how you may discourage using the latest version of python. Though I'm unaware of the downsides to using virtual environments, besides the added complexity. In the documentation, I saw a line about how virtual environments |
One things at a time. There are people here that have 2 weeks experience. I'm having a difficult enough time helping with the most basic of problems. The latest Python doesn't show table colors. I don't know what else they broke. There's zero reason these beginners should be on the bleeding edge. Two or 3 of us spent several days debugging 3.7.4. If someone can tell me the 3.7 feature they need, then I'll endorse. So far, it's 0 for 20 when I ask the question. Speaking of which, if you're running 3.7, what feature are you using? |
Right now I'm just using type hints, specifically forward-referenced annotations which are only able to be used in python 3.7, according to this. I like using type hints. I'm aware that I can use strings for type hints in earlier versions of python, but it feels weird to see quotation marks outside of literal strings within the body of my code. |
OK, that's better, your 1 out of 21 has a use for 3.7. I'll further explain in the docs that if you really know what you're doing, then sure, go nuts, but even then, stay off the absolutely latest and greatest. I use type hints too, but because of the backwards compatibility I use the comments based type hints. They work extremely well with PySimpleGUI in particular. They're for my use, not the PySimpleGUI user's use. Enables code completion basically. I also like them because I never forget the format: |
You must use the documentation and demo programs to find the quickest answers or to find your answers period. You will NOT be successful guessing your way through this package and posting an issue when you run into each problem. Not saying you're doing that... it's a caution is all as some people do try this. Use the version with a table of contents: Press Control+F and search. This is what I do. You are not going to get 1000's of hits back. It's something to be embraced. Each element is not THAT much documentation., If the document is too much, then use the python help system as the doc strings are really close to finishing. |
Type of Issues (Enhancement, Error, Bug, Question)
Enhancement
Operating System
Linux (manjaro-xfce-18.0.4-stable-x86_64),
Windows 10 64bit
Python version
3.7.3 64 bit on linux
3.6 32bit on windows
PySimpleGUI Port and Version
PySimpleGUI 3.39.0, tkinter
I am re-designing my application in PySimpleGUI "former design was wxpython", everything simple and make the design process a task for humans
just a small issue, my design looks as expected in linux "Manjaro" but not ok in windows, attached are 2 snapshots of my application running on both operating systems, the one on windows shows smaller space out and elements doesn't fit correctly in main window frame.
my suggestions is either:
add a size by pixel for every element, which you can see in my sample screenshots the progress bars sizes are the same on both systems because we use pixels instead of character size "i know it's not an easy task, too much mods"
or designing a new element "may inherits from sg.Text" but acts like an auto stretch spacer that can fill the remaining space of the row to match main window width, something like a spacer in wxpython.
for example:
layout = [[sg.spacer(ratio=2), sg.Text('Hello'), sg.spacer(ratio=1)]]
say we have main window size is 100 pixel and "hello" text size is 25 pixels, the remaining pixels are (100-25=75 pixels) should be divided according to the spacer ratios to:
--- 50 pixels --- "Hello" --- 25 pixels ---
Application snapshot on Linux "Manjaro" looks Ok as expected:

Application snapshot on Windows10, spacing is not correct:

my code:
i tried to include only the design and simplified the code as much as i could
The text was updated successfully, but these errors were encountered: