I have a python program which has a button to popup a Toplevel windows in the center.
I can use Toplevel.resizable(0, 0) to limit the size of window, but i want to limit the position of windows and can't move the window by mouse.
How can i do this?
You can use Toplevel.overrideredirect(True) to make the Window Manager ignore this window. This removes the title bar and borders, thus preventing the user from moving it, but this also removes it from the taskbar.
Related
I'm writing a file management and config file editing app in Python 3.10 with Dear PyGui as the GUI library. I would like to place a group at the bottom of the window so it:
Stays at the same place when the rest of the content in the window changes
Stays at the same place relative to the lower left (or right) screen corner when the user changes the size of the viewport
I know how to do 1, I can just use pos=(10, dpg.get_viewport_height()-75).
I don't know how to do 2. The above seems to do it upon launch and if you don't resize the viewport, but it doesn't actually anchor them to that relative spot as the window size changes:
To anchor the group to the bottom, you need to update its position on the window resize. Dear PyGui has a callback that fires every time the window is resized: dpg.set_viewport_resize_callback(update) where update is a function that, in this case, runs dpg.set_item_pos("bottom_buttons", (10, dpg.get_viewport_height()-75)). This will keep the buttons positioned at the bottom of the screen.
There might be a better way to do this, and doing it this way might have consequences for overlapping content later on, but it's the easiest way to implement it that I have tried.
CleanMyMacX image
As you can see, some of the buttons are outside of the window, and the window's title isn't visible. I am wondering if this is possible to do in python tkinter, and if so, how to do it.
Thanks!
I am working on a Frameless window for modern GUI with Tkinter. I have implemented a drag window feature but It is also working when window is behind of the taskbar, it is a big problem when I am trying to recover my window from behind of taskbar. So I want to disable the drag feature when the mouse reaches on taskbar's border.
def drag(event):
act = str(event.type)
if act == 'Motion':
global _app
#_app is a reference to root in other py file
t = _app.geometry().split('+')[1:]
xval = int(t[0])
yval = int(t[1])
_app.geometry('+'+
str(xval + event.x -400)+
'+'+str(yval + event.y -20))
#window size is fixed i.e. 800x480
When you makes a window border-less using overrideredirect() method, then this method says to operating system's windows manager to just ignore your tkinter's GUI window.
When you do this then the windows manager now takes no any responsibility for your GUI window. Each and every task like window dragging, minimization and maximization, closing event etc should be handled by you manually.
Now to solve you dragging problem on windows taskbar there are two ways.
1) As I told you before that do everything manually, then you should to locate your windows taskbar manually and then modify your drag function to prevent your mouse motion after the borders of your taskbar.
2) The simplest way is to make your GUI window a top level window by which you will able to drag your window onto the taskbar without any window hiding problem.
To make the window top level you should just set an Attribute i.e. topmost = True.
root.attributes('-topmost',1)
So basically I have a window thats just a vertical list of buttons. I want to create a dropdown menu that goes off to the side without changing the size of the window. I am trying to do this with popover, but now I have the problem where my popover gets cut off by the window. Is there a way I can make it bleed past the window boundaries?
Popovers don't go wider than the parent window. You could have a try at a GtkMenu. They are allowed to go wider than the window, up to the width of the monitor.
With PyGTK running on Windows, I want to have a new window pop up near a parent window, but never off-screen.
I observed the behavior I want in Microsoft Wordpad in both Windows 7 and Windows XP. If you make the window very small and move it to the bottom right of the desktop, right click in the text field, and open the Paragraph menu, the dialog pops up fully visible. This happens even if the Wordpad window is partially off-screen. The child dialog does not pop up in a fixed position relative to the main window. It just pops up close, and fully visible.
My application consists of a main screen which spawns child windows that block the rest of the application until the user is finished using them. The user may have to open and close many child windows in sequence, so I want them to appear near where they click on the button, so the user doesn't have to move the mouse all over the screen.
I tried using gtk.WIN_POS_MOUSE, but when the main menu is near an edge of the screen; the child window that spawns often ends up partially off-screen.
I would expect that a call to set_transient_for(main_menu) on a child window should inform Windows that I want my window to be near its parent. However, Windows just places it at the top left of the desktop -- not even necessarily on the same screen as the main menu.
The following code will demonstrate the problem by popping up a window at the bottom left of your screen that contains a button which spawns a subwindow when clicked:
import gtk
class MyWindow(gtk.Window):
def __init__(self):
gtk.Window.__init__(self)
self.connect("delete-event",self.on_delete_event)
button = gtk.Button("Open Subwindow")
button.connect("clicked",self.open_sub_window)
self.add(button)
self.set_gravity(gtk.gdk.GRAVITY_SOUTH_EAST)
self.show_all()
width, height = self.get_size()
self.move(gtk.gdk.screen_width() - width, gtk.gdk.screen_height() - height)
def on_delete_event(self, widget=None, data=None):
gtk.main_quit()
def open_sub_window(self, widget=None, data=None):
w = gtk.Window()
w.set_size_request(200,200)
w.set_transient_for(self)
w.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
w.show()
if __name__=="__main__":
MyWindow()
gtk.main()
As you can see, the sub_window shows up partially off-screen.
If you comment out the line w.set_position(gtk.WIN_POS_CENTER_ON_PARENT) you will see that the Windows window manager just places the subwindow at the very top left of the desktop. Not very useful!
Is there a way to get the desired behavior without resorting to manually managing Window positioning by checking what location the window ends up at and then moving the window to a fully off-screen position?
UPDATE:
I filed a bug report for pyGTK on Feb 23, 2011: http://bugzilla.gnome.org/show_bug.cgi?id=643138
It has not yet had any responses from the devs or other users. If you are having this problem please chime in on the bug so it gets fixed (or so that we might get a workaround).