Python tkinter app, ttk-heavy, pretty on MacOS, ugly on W10 - python

I'm making a Python3 app with tkinter for GUI. I intend to make binaries for MacOS and Windows, and that was one of the reasons why I choose tkinter. I am using ttk for the widgets, and I was under the impression that that would automagically look great on all OSes.
But the colours are different. The distances to other widgets and borders are different. The button with a lot of text isn't wide enough. Frankly it just looks like crap on W10.
Is there some trick to getting it to look good on both of these two OSes, such as though certain styles?

The ttk widgets on each platform have their own default colors, margins, borders, fonts, etc. It is by design that they look different on different platforms.
Unfortunately, that means that you may have to add some platform-specific code from time to time to account for this. For example, you can add a little padding to the button, and you can manually set the color of the labels, or use geometry manager options to get them to fill the whole width of the screen with the same color.
Your goal is obtainable, but it will require a little more work to get it to look its best on all platforms.

Related

Resizing an icon doesn't show on GUI

I am trying to make my GUI icon go bigger.
I tried this:
MainWindow.setWindowIcon(QtGui.QIcon('Logo1.png'))
MainWindow.setIconSize(QtCore.QSize(128,128))
When 'Logo1.png' is 128x128
When I change numbers SetIconSize line, like this:
MainWindow.setIconSize(QtCore.QSize(500,500))
It doesn't show on my GUI.
My questions are:
Does this happen because I need my logo to be smaller something like 28X28?
If I need a specific size, what size is it and how do I make my logo this size?
Even if I do need a specific size, why wont setIconSize change my icon size?
The iconSize property documentation of QMainWindow explains that:
[The] size of toolbar icons in this mainwindow.
As you can see, it has nothing to do with the windowIcon.
It is up to the underlying OS and its window manager to decide the size of the icon, whether its shown in the window decoration (tipically in the title bar), the task manager/window switcher or anything else, and you don't have any control over it through Qt.
The only "exception" is when drawing client-side windows: windows for which the whole decoration is drawn by the program (the title bar with its system buttons and icon, the frame around the window, etc.).
That is, though, something that is usually discouraged as it's hard to achieve without facing various difficulties (both with drawing and interaction); it also makes the window appearance inconsistent with the whole system and could also create issues with accessibility for visually impaired people.

Visual Basic like GUI for Python with arrays of text boxes and labels

There are lots of GUI environments for Python like Qt, tKinter, wx, PySimpleGUI, etc. so I have not been able to go through very many of them. I would like to know if there is one which is
somewhat similar to Visual Basic's (drag and drop and resize),
allows for arrays of textboxes and labels.
It should preferably be open source,
should create stand alone *.exe files,
and not requiring browsers.
The closest match to your requirements is probably PySimpleGUI. Doesn't have drag and drop, but you don't really need it. It takes 1 line of code to configure and place a widget into your window. You easily make an "array of textboxes and labels". Runs on tkinter or Qt.
Would that there were a simple drag and drop GUi builder for Python!
You might try appJar. It's not drag and drop but it seems pretty straightforward.
QtDesigner is drag and drop. It's part of the PyQT suite. QtDesigner creates XML (.ui) files which can then be translated to .py files. Michael Herrmann's site
shows how to do this with a minimum amount of overhead.
I personally recommend my project https://github.com/cdhigh/tkinter-designer.
tkinter-designer implemented a add-on in VB6, you can design your GUI in VB6 (drag and drop, resize, align, color, key-bind,...), and then this add-on generate a complete code frame. what you will do is add logic code in event method like coding in VB.
PS: You can install nano version of vb6.

Python tkinter - windows larger display settings

My problem is when somebody runs my tkinter gui (in Windows 7) and has larger display settings (125%), the gui doesn't look well (buttons are closer to each other, end of text cannot be seen, etc.). I use place method with x - y coordinates to place the widgets.
Maybe using pack method could solve this, but it is easier to use place for me, because there are lots of labels and buttons with exact places.
Another solution can be if the display settings could be checked with pywin32 and resize everything if needed. If it is possible, please confirm and help, what is the related function or if you have any other idea/advice, please share it.
This is one of the reasons why place is a poor choice. You should switch to using grid and/or pack. They are specifically designed to handle different screen sizes, different resolutions, different widget styles, and different fonts.

How to get multiple panels in one window - GTK+

I am looking to know what is the best practice to make a window which the content changes, but without changing the window. Something like using tabs, but with no tabs, controlled with buttons.
What widget should i use to archive what i need?
And if you don't mind the little off-topic, should it be drawn manually or with a GUI designer like glade?
It is meant to be used within python.
If you can use GTK 3.10, take a look at GtkStack and GtkStackSwitcher. If not, use GtkNotebook and set the show_tabs property to False, then build your own buttons.

GUI-embeddable Python drawing widget with anti-aliasing

I am writing a small diagram drawing application (similar to Graphviz in spirit), and need a GUI library that would allow me to embed a canvas capable of drawing anti-aliased lines and text. I want to have a text editor in one half of the window to edit the diagram code and a (perhaps live) preview pane in the other.
Right now I have the text editor in a tkinter window and the rendered diagram in a separate pygame one. This technically works, but it's messy (e.g. having two event loops), and in general I would much prefer having both parts in one window. I have searched for ways of integrating the two, but haven't been able to find anything cross-platform, and pygame explicitly suggests not trying to do it.
An alternative would be to have pygame export the image into a file and load it back into tkinter, but tkinter can read only GIF/PPM without PIL (and I use Python 3, which PIL doesn't support) and pygame can't write GIF/PPM. I could backport to Python 2, since it's a tiny app, but even then, having a large extra library for a simple image conversion doesn't seem right, and the round-trip to a file will probably be too slow for live preview (not to mention ugly).
Finally, a simple tkinter canvas is almost what I want, except it can't draw anti-aliased lines, and for a program whose main purpose is to draw line figures, that is not acceptable.
I'm using Python 3 so libraries that support it are preferred, but if there's no way to do that whatsoever Python 2 libs are Ok as well. The library needs to be cross-platform, and of course, the fewer external packages are required, the better.
If you don't mind the way GTK looks, pygtk has an option for antialising in their canvas widget (see this) and is considered by many to be as powerful as Tkinter, though it is not included in standard Python installs.
Also, it's Python 3.x compatible, which can't be said of most non-standard library modules and packages.
Screwing around with Tkinter+pygame is silly. I would use wxPython. In fact, I've done a diagramming widget using wxPython, and it has anti-aliasing:
Unfortunately it was for work, so I can't distribute the code.
The wxPython classes you want to look at for anti-aliasing are wx.GCDC and/or wx.GraphicsContext.
After a thorough search I ended up using PyQt4. It does fit all my requirements (Python 3, cross-platform, anti-aliasing), and now that I've gotten through the basics, it's also quite intuitive and easy to use.
Posting this as an answer to my own question and accepting it for future reference.

Categories

Resources