Tkinter has this method:
window_name.attributes('-fullscreen',True)
and customtkinter?
I haven't found anything but
geometry(f"{WIDTH}x{HEIGHT}")
However when I grab screen size and put as WIDTH & HEIGHT the screen does change the size but does not go full size, I mean it is always shifted to the right so the windows leaves the margin on the left and top and the part of the window goes out of the screen to the right.
Related
So my application's main part consists of a QFrame which contains 2 other QFrames (left one for a menu, right for the content of the current page selected) I made the layout in QtDesigner as follows:
I added an animation for opening/closing the menu on the left, making the QPushButton texts visible when open, hiding them when closed (Only the icon shows in that case) by increasing the QFrame's width.
def ToggleMenu(self):
width = self.ui.frame_left_menu.width()
defaultWidth = 70
toggleWidth = 200
if width == defaultWidth:
toggleWidth = 200
self.ui.frame_content_right.lower()
self.ui.frame_left_menu.raise_()
else:
toggleWidth = 70
self.ui.frame_left_menu.lower()
self.ui.frame_content_right.raise_()
self.animation = QtCore.QPropertyAnimation(self.ui.frame_left_menu, b"minimumWidth")
self.animation.setDuration(300)
self.animation.setStartValue(width)
self.animation.setEndValue(toggleWidth)
self.animation.setEasingCurve(QtCore.QEasingCurve.InOutQuart)
self.animation.start()
ToggleMenu() is called when the user clicks on the menu button (thats outside of frame_center, increasing/decreasing its width.
When opening the menu, its width is increased, thus pushing the right QFrame along, making the available space smaller for actual content.
I would like to be able to make it so the menu is displayed above the content QFrame when opened. I tried calling raise_() and lower() on open/close, but that doesn't seem to change anything, I think that is because they are not overlapping to begin with, given the layout above.
I would like to avoid creating the layout at runtime if possible. How could I solve this?
I'm working on an image annotation tool using Tkinter. A rectangular bounding box is following the cursor and is placed on the image by clicking. Now I need to be able to resize the bounding box and I'd like to do it in a similar fashion as it's done in Photoshop, holding down a button and depending on where the mouse is moved, the brush changes in size. Is that possible in Tkinter?
I've come up with this, where I wanted to add the pointer distance traveled in each direction to the rectangles size:
self.canvas.bind('<Alt_L>', self.resize)
self.previousx = 0
self.previousy = 0
def resize(self, event):
x = self.canvas.canvasx(event.x) # get coordinates of the event on the canvas
y = self.canvas.canvasy(event.y)
self.rect_size[0] += (self.previousx - x) # width
self.rect_size[1] += (self.previousy - y) # height
self.motion(event)
self.previousx = self.canvas.canvasx(event.x)
self.previousy = self.canvas.canvasy(event.y)
It kind of works too but
the previous coordinates need to be initialized with a different key first which is very annoying and
when the cursor - and with it the rectangle too - changes position it is very hard to tell if the rectangle is already the proper size.
How can I keep the cursor at the same spot and still get the mouse movements?
Edit:
Bryan in the comments was right, you can't move the mouse without also moving the on-screen cursor, which is true at least for my purposes. The solution was very simple, while resizing the bounding box I stopped updating it's position, so while the mouse was still moving, the rectangle did not.
Bryan in the comments was right, you can't move the mouse without also moving the on-screen cursor, which is true at least for my purposes. The solution was very simple, while resizing the bounding box I stopped updating it's position, so while the mouse was still moving, the rectangle did not.
I am making a basic text editor and I am saving the scroll position in a file on closing the program. Then when opening the program it will read the scroll position from the file and update it so you can continue where you left off.
I can get the position fine from scrolledtext.yview() which returns a tuple with e.g. (0.42, 0.75)
But I cannot figure out how to change the scroll position. I have tried scrolledtext.vbar.set(0.42, 0.75) to try and update it but that doesn't work as in it doesn't do anything and gives no errors. I have also tried scrolledtext.yview(0.42, 0.75) but it says TclError: bad option "0.42": must be moveto or scroll so if anyone knows how to update it that would be greatly appreciated, cheers.
Edit(Code):
import tkinter as tk
root = tk.Tk()
Frame = frame(root)
Frame.pack()
textbox = ScrolledText(Frame)
textbox.pack()
textbox.yview() #this is saved to file, produces tuple of e.g. (0.42, 0.75)
textbox.vbar.set(0.3, 0.7) #this doesn't produce any errors but doesn't change the scroll position
textbox.yview(0.3, 0.7) #this is also something i have tried but produces the error _tkinter.TclError: bad option "0.4243827160493827": must be moveto or scroll
root.mainloop()
You can't expect the saved yview to work in all cases. If the file has been edited, the proportions could be all wrong.
The tuple you get from yview represents the fraction visible at the top and the fraction visible at the bottom. You can call yview_moveto to set the position at the top, and then let tkinter take care of the fraction at the bottom.
For example, if the yview you've saved is (0.42, 0.75), then you just need to call yview_moveto('0.42'). This will cause the view to be adjusted so that the given offset is at the top of the window.
In case of widgets update with change bbox sizes, i use a followed snippet to keep scroll position:
#before repaint store vsb position caclulated in pixels from top
bbox = canvas.bbox(ALL)
self.mem_vsb_pos = canvas.yview()[0] * (bbox[3] - bbox[1])
#after repaint (back calculation):
bbox = canvas.bbox(ALL)
canvas.yview_moveto(self.do_vsb_pos / (bbox[3]-bbox[1]))
#before repaint - if need repaint from top
self.mem_vsb_pos = 0.0
I am using python turtle library to draw a big diagram. Whenever it's drawn the displayed region is the center (i.e. the scrollbar's are in the middle position). I'd like to scroll to the top-left region. Is there any way to do that?
Found solution:
ts = getscreen().getcanvas()
ts.xview_moveto(0)
ts.yview_moveto(0)
You can also make the screen bigger and you can manually scroll it.
screen = turtle.Screen()
screen.screensize(x ,y)
Just make the x bigger and you can scroll manually (by default the x is 400 and the y is 300)
I'm working on a project using Python and pyGTK. I have a window whose only purpose is showing an image. Unless the image is too big to fit the screen, the window should show no scrollbars by default.
So what I do is something like this:
window = gtk.Window()
window.resize(image.size[0], image.size[1])
scrolled = gtk.ScrolledWindow()
scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
scrolled.set_shadow_type(gtk.SHADOW_NONE)
area = gtk.DrawingArea()
area.set_size_request(image.size[0], image.size[1])
window.add(scrolled)
scrolled.add_with_viewport(area)
area.show()
scrolled.show()
window.show()
But it doesn't quite work. The resulting window is a little too small, and thus, scrollbars show up.
For it to work, I have to thange the second line to this:
window.resize(image.size[0] + 2, image.size[1] + 2)
But that is ugly, and it doesn't work under all systems. In my Windows box I have to use + 3.
What can I do to make sure the window is big enough for the image?
I figured it out :).
If you put a DrawingArea inside a ScrolledWindow, things just won't work as they should. Instead, you have to put the DrawingArea in a Viewport, and the Viewport in the ScrolledWindow. gtk.ScrolledWindow provides a method, gtk.ScrolledWindow.add_with_viewport, that does this automatically, for convenience's sake. The problem is the viewport generated by that method has a border by default, and that border varies in width depending on the system. Also, there's no way (that I know of) of accessing the generated Viewport (edit: you can use scrolled.get_child()) to get rid of the border. The solution is simple: you have to manually create the Viewport.
window = gtk.Window()
window.resize(image.size[0], image.size[1])
scrolled = gtk.ScrolledWindow()
scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
scrolled.set_shadow_type(gtk.SHADOW_NONE)
viewport = gtk.Viewport()
viewport.set_shadow_type(gtk.SHADOW_NONE) // Get rid of the border.
area = gtk.DrawingArea()
area.set_size_request(image.size[0], image.size[1])
window.add(scrolled)
scrolled.add(viewport)
viewport.add(area)
viewport.show()
area.show()
scrolled.show()
window.show()
It worked like a charm on Arch (GNOME 3), Windows XP, Windows 7 and Ubuntu (Unity).