Menubuttons located in the middle of menubar - python

how do I put my menu bar buttons on menu bar's left ? Right now I pack() them with side=LEFT but still they're in the middle. Here's the code for my menu bar: http://pastebin.com/bgncELcb

I recommend against creating menubars a) with frames and menubuttons, and b) with menus in non-standard places. You should use the menu option of your toplevel window if you're at all interested in usability. However, since you specifically asked about menubuttons in the middle of a frame...
If you want something precisely in the middle, one thing you can do is break your menu into three sections, a left, middle and right. Place those three subframes inside your "menubar" frame. Use grid to give the left and right sections the most weight (and equal to each other, so the middle stays in the middle). You can then pack a button or buttons in the middle frame and they will remain in the middle.
Another choice is to use place, and set the relative X position to .5 and the anchor to "n". That is probably the easiest, though you can have problems with overlapping buttons if they don't all fit because the user resized the window.
The option you chose -- pack -- is the most difficult route to take. pack by it's very nature is designed to pack things along edges. Again, you can use three subframes, but pack isn't the natural choice here.
My advice: rethink why you want a non-standard menubar. Use a real menubar with menu buttons along the left like 99.9% of all other apps in the world. Your users will thank you.

What does menubar.pack(side=LEFT) give you?
Can you also try with menubar.pack()?

Related

How to move canvas drawn shapes to have a fixed position on screen?

I have a GUI that I've made in tkinter using a canvas that has a bar along the left side and a bar along the top containing information. In the remaining area various rectangles are drawn corresponding to the information in those bars I described. The issue is, when you scroll away on the canvas, those events will leave as well.
Basically, I want to create a visual effect like position: fixed is in CSS where these bars on the side and the top stay in place relative to the rest of the canvas so that they don't move from their relative position while scrolling.
I tried making use of the scrollbar commands, but have had trouble making my own function there. I also tried to see if there was an event I could bind to the canvas to track the movement so that I could move the bars myself but I could not find anything.
There is no way to do this directly in the canvas unless you write the code to move the items in the top and left whenever the user scrolls. It would probably require a fair amount of work.
However, it's trivial to have separate canvases for the side and top that do not scroll, and a third canvas that has all of the scrolled data.
I was able to end up solving my own issue by adapting the solution from: How can I add Unscrollable Image to a frame/Canvas?
Simply put, I made my own yview and xview functions that would scroll my desired "bars" with the window by moving the objects.
Special thanks to #jasonharper for his help.

PyQT how to change layouts size

I am trying to make a GUI that is very similar to Spotify using PyQT
I've already designed the main window and I am struggling with applying the design to QT Creator.
This is what I want it to look like
But I'm trying to use Layouts in order to organize every widget.
For example
Image of the main window, split into 3 parts
like in the sketch I've made the software will be split into 3 parts, left bar, mid which is where the explore title is and right bar.
The problem I have is that I can't control the layouts size and the size of what's below them for example in the sketch the mid bar is wider than the right bar and the right bar is wider than the left bar but in the QTCreator I've no idea how to change the width and height of objects inside Layouts.
The first option (which I personally prefer) is to fill your layout with it's contents first (buttons, labels, etc.). This will already start to scale your layout, if there are more buttons in the middle bar than on the other bars. If your layout still isn't what you want it to be, you can use Spacers. They can push and pull puttons and position the in relation to other parts of the layout, as well as to the layout itself. The scaling will be adjusted automatically according to the spacers position.
This option has the advantage, that your application will be correctly scaled and not completely chaotic when it is run on a device with a display aspect ratio which is not the same as the one of the machine your developing it on.
There is, however, also a minimumSize and maximumSize attribute to the layouts, which provide a much more straightforward possibility, but sometimes cause your layouts to become very weird when adding or removing a button, or changing the text of a label. More on this option can be found in the Qt docs:
https://doc.qt.io/qt-5/qlayout.html

Splitter window display issue

I am writing a program which has a TreeCtrl on the left and a RichTextCtrl on the right.
Following is the code of the splitter, panel and other elements.
The problem is that in windows, the bottom of the treectrl and textctrl is hidden. The statusbar covers the bottom of the splitter. But even after removing the statusbar I cannot see the bottom of the treectrl (hides up to 6 rows).
self.panel=wx.Panel(self,wx.ID_ANY)
self.splitter=wx.SplitterWindow(
self.panel,-1,size=wx.DisplaySize(),style=wx.SP_LIVE_UPDATE)
self.splitter.SetMinimumPaneSize(5)
self.datatree=wx.TreeCtrl(self.splitter,1,style=wx.TR_HIDE_ROOT|wx.TR_ROW_LINES)
self.display=wx.richtext.RichTextCtrl(
self.splitter,1,style=wx.VSCROLL|wx.HSCROLL|wx.WANTS_CHARS)
self.display.SetFont(self.displayfont)
self.handler=wx.richtext.RichTextXMLHandler()
self.splitter.SplitVertically(self.datatree,self.display)
self.logger=self.CreateStatusBar()
I think the issue here may be that you've explicitly told the SplitterWindow to take up the entire display size. Try omitting the size argument to the constructor, or adjust it down some, to see if that has any effect.
If omitting the size parameter does not help, I'd suggest creating Panels with Sizers that contain your Tree and your Rich Text Control, then splitting those Panels vertically within the Splitter Window.

Allow a ToolItem to fill horizontally in a Toolbar

SO.
I've been busy working on a project in python and pygtk. I want to have (at the top) a "Toolbar" with back, forward etc. buttons and a long Entry that would take the rest of the horizontal space. I don't get the desired effect, however, as the space the Entry takes is quite limited.
self.omnicont = gtk.ToolItem()
self.omni = gtk.Entry()
self.omnicont.add(self.omni)
I've tried set_child_packing (which doesn't apply to Toolbars, it seems). I couldn't find any other way.
The buttons I have are declared in this way:
self.bBack = gtk.ToolButton(gtk.STOCK_GO_BACK)
and similar, so I don't think it's possible to put buttons like this in an HBOx.
How can I have the Entry take all the available horizontal space and, if that's not possible, how could I get an HBox to contain buttons with the stock icons?
Accordingly to the docs you can use:
set_expand(True)
on the item you want to expand.

Difference between "grid" and "pack" geometry managers

What's the main difference between the Tkinter geometry managers grid and pack?
What do you use for your projects ?
If grid is better to align object, what the main purpose of pack?
grid is used to lay out widgets in a grid. Another answer says it "overlays a graph" which is a bit of a misnomer. It doesn't overlay anything, it merely arranges widgets along row and column boundaries. It is great for creating tables and other structured types of layouts.
pack lays things out along the sides of a box. It excels at doing layouts where everything is on a single row or in a single column (think rows of buttons in a toolbar or dialog box). It's also useful for very simple layouts such as a navigator on the left and a main work area on the right. It can be used to create very complex layouts but it gets tricky until you fully understand the packing algorithm.
You cannot use both grid and pack with widgets that have a common parent. Your app may work but it is much more likely to get into an infinite loop as each manager tries to layout the widgets, then the other notices the widgets change size and try to adjust, etc. etc.
The third manage is place. Place is great for doing either absolute positioning (ie: place widget at a given x/y) or relative (eg: place a widget on the right edge of some other widget).
While you cannot mix grid and pack within the same container (a container is typically a frame), you can use both grid and pack within a single application. This is very, very common since each has strengths and weaknesses. I use both on a regular basis.

Categories

Resources