I've got a wx.Toolbar and I'd like to make the buttons larger. I've searched and can't seem to find any concrete documentation on how to do this.
I'm also wondering how well this will translate across platforms; what will happen to the buttons and icons on OSX?
It depends on what you want to change: is it the size of the buttons or the size of the icons ?
To change the size of the buttons, use SetToolBitmapSize (24x24 for instance):
toolbar.SetToolBitmapSize((24, 24))
This will only change the size of the buttons, though. If you want to change the size of the icons, simply use bigger ones. The easiest way is to use wx.ArtProvider:
wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, (24, 24))
So, summing it up:
# Define the size of the icons and buttons
iconSize = (24, 24)
# Set the size of the buttons
toolbar.SetToolBitmapSize(iconSize)
# Add some button
saveIcon = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, iconSize)
toolBar.AddSimpleTool(1, saveIcon, "Save", "Save current file")
Remark: As SetToolBitmapSize changes the size of the buttons, not the size of the icons, you can set the buttons to be larger than the icons. This should leave blank space around the icons.
Doesn't the size of the toolbar adapts itself automatically to the size of the bitmap icons? I think if you want a bigger toolbar, you need bigger bitmaps.
On Mac OS X Big Sur running python 3.9 and wxpython 4.1.1. this call
toolbar.SetToolBitmapSize((24, 24))
does not work. The algorithm seems to be that of the icons associated with the toolbar wxPython picks the largest one and sets that size for all the other icons.
Related
So Qt Designer has this feature where you can resize the window you're working on. And that's fine and dandy, but every now and then, I accidentally drag it, and the window gets larger or smaller than I wanted it to be. The undo action doesn't undo the resizing, so that's a bummer. Also setting max and min sizes for the central widget doesn't do anything to fix this issue.
Is there a way I can have the window size locked?
Here's a demo:
Use QWidget::setFixedSize(w, h) for explicitly set width and height or QLayout::setSizeConstraint(QLayout::SetFixedSize) if you want the fixed size to be determined automatically based on content.
I have written a guizero code that creates a new window with different amounts of information on it depending on what is selected. I was just wondering if there is a function to resize the window to fit all of the information. I am currently just making the window big enough to fit the largest amount of information but I would rather have it so it resizes it automatically.
And also is there a simple function so that if the window size is changed all of the widgets inside of it change size as well?
I think is not possible to automaticly resize the window but you can count the number of lines and resize the window.
numLines*defaultHeightByLine + height of the other elements
I am new to Tkinter and still learning. My desktop resolution is 1366x768 and I am developing for an environment which is 2048x768. Right now I am setting the window resolution by detecting it like this -
w = main_container.winfo_screenwidth()
h = main_container.winfo_screenheight()
main_container.geometry(str(w) + "x" + str(h))
Now I have several screens and I cannot use grid on each and every screen. Like I have a Login Screen in which I have a Frame like this-
self.frame_background = tk.Frame(self.frame_parent, bg='#ffffff')
self.frame_background.pack(fill='both', expand=True, padx=100,
pady=100)
This is just an example of one widget. Since values for padx and pady are fixed with 100, if I am running my application on a 640x480 resolution device, the layout gets too stretched and almost nothing is visible inside this frame.
How can I set these padx and pady and other width and height values dynamically according to the screen size and resolutions?
Now I have several screens and I cannot use grid on each and every screen.
Why can't you? There's nothing preventing you from using grid on every screen. Though, it's actually quite common to mix and match pack and grid in different frames, and arguably a best practice.
Like I have a Login Screen in which I have a Label like this...
The code following that statement doesn't have a Label, so it's hard to know what you are trying to do.
if I am running my application on a 640x480...
First you say you have a desktop resolution of 1366x768, then say you are targeting 2048x768, and are now asking about 640x480. That's a pretty wide range of values. If you have to support something as low as 640x480 you definitely should not be hard-coding padding to such huge values. Typically padding is never more than one or two. Tkinter apps can be made to accommodate that wide range of screen sizes, but that relies on not hard-coding the size of widgets and padding as much as possible.
How can I set these padx and pady and other width and height values dynamically according to the screen size and resolutions?
Generally speaking, you shouldn't do that. The general rule of thumb with tkinter is that you make the widgets the smallest size they need to be and let the geometry managers worry about stretching or shrinking them to fit the available space. There are a few exceptions to that rule, but in general, that rule works quite well.
Unfortunately, geometry management questions are hard to answer without knowing more about what you're trying to do. For example, we need to know why you think you need padding of 100 pixels. That seems highly unusual. Plus, we need to know what else is in your frame, what your frame is in, and so on.
My advice is to remove the padding, or set them to very small values. Then, make sure you use all of the geometry manager options that are available to you, such as fill and expand with pack, and sticky and others for grid.
Is it possible that when a Tkinter window is made bigger or larger, everyhting in the window is scaled?
So all the proportions stay the same but their sizes vary.
Now when the window is resized all the buttons etc stay the same so I disabled resize because there is no point, it just looks bad.
No, it is likely not possible, depending on what you mean by "everything" and what you mean by "scaled". Any widget can be made to stretch to fill its allotted space. Text widgets and canvas widgets, for example, scale nicely. A button or label will fill the space it's in, but the text inside the widget won't change (that is also true of text and canvas widgets).
It's possible to organize your GUI so that when the window resizes, everything remains in its proper place at its original size. Having buttons that automatically scale is not something most people would expect. Disabling resizing usually results in a poor user experience -- users should have the ability to make a window larger or smaller.
I'm working on a Tkinter application using the Grid geometry manager (It's my first time using Grid, and I love it! :D) that contains a scrolling listbox that displays options whenever a user selects an option.
It's working well, but the window is small and ugly. When I maximize it, everything else resizes fine (thanks to columnconfigure) but the listbox stays the same height. Is there a simple way to fix this?
(I have seen this question but it's for Pack, not Grid)
Thanks in advance.
Code sample because one was asked for:
self.tasklist = Listbox(self.frame, exportselection=0)
self.tasklist.grid(row=1, sticky=W+E+N+S)
yscroll = Scrollbar(self.frame, command=self.tasklist.yview, orient=VERTICAL)
yscroll.grid(row=1, column=1, sticky=N+S)
Without seeing more of your code it's impossible to say. Most likely your listbox is expanding properly, but your self.frame is not. Though, I don't see you giving any weight to the row and column that the listbox is in, so that could be a factor.
An easy way to debug this is to give self.frame a garish color that will stick out (red, bright green, etc). Then it will be easy to see if the listbox is properly resizing inside the frame, and if the frame is properly resizing inside its parent.