how to make tkinter window not moveable with the mouse - python

very simple problem, I just try to make tkinter window that you are not able to move with the mouse. the problem is that I don't find a function that can do it, the only thing that I found is making it not resizable and stuff like that, I also found a function that hides the bar and making it not resizable or moveable, but it doesn't help me cause I still want it to have the default window bar, let's just say I have a normal window here:
import tkinter as TK
window = TK.Tk()
window.geometry('1200x800')
window.mainloop()
so just tell me if you know how to make it impossible to move the window with the mouse, how to do that, the code should work fine with fullscreen and other functionality like that by the way.

Related

tkinter Button widget 'inside' another button widget-tkinter

I need to make an application, in which I need to place a tkinter button widget-'b1', inside another tkinter button widget-'b2'.
b2,however disappears and appears only after mouse is hovered over it.
Made a simple code without using OOP. Firstly made a master root window,added button 'b1'. Then using 'b1' as a master, added button 'b2'. The callbacks of both buttons are different. The problem is,button 1(in light blue color) appears normally visible. However second button(in red color) doesnt gets displayed. It appears only when you hover the mouse over it.
import tkinter as tk
root=tk.Tk()
b1=tk.Button(root,height=7,width=10,bg='light blue',command=print('B1'))
b1.place(x=0,y=0)
b2=tk.Button(b1,height=3,width=5,bg='red',command=print('B2'))
b2.place(x=2,y=2)
root.update()
Is it possible that both buttons are displayed simultaneously?.
Help is appreciated. Thanks in advance
This version of code is just for simplification. Later will implement more buttons and OOP as well. Sorry for mistakes if any.

Add button to Tkinter Window panel before minimise, maximise buttons

I have developed a Tkinter GUI and need to add a button in the GUI window top panel, next to the minimise, maximise and close buttons. The button then calls a function. How can this be done?
Tkinter doesn't have any support to do what you want. You'll have to find some sort of platform-specific library to alter what is shown in the window border.
Your only other option is to turn off the window border provided by your OS with overrideredirect, and then create your own border with whatever controls you want. This requires a lot of work because you also have to write the code for moving and resizing the window, but it's possible.

Python Turtle - Disable Window Resize

Is there a way to disable the window resizing in the Turtle module?
E.G - Disable the maximize and minimize button and disable the ability to drag the window out or in. Thanks!
There's another way of doing it which is a little more 'hacky' but works well for projects that are already written using TurtleScreen and not a RawTurtle. It is actually a one-liner:
screen = turtle.Screen()
# ...
screen.cv._rootwindow.resizable(False, False)
This accesses the root window of the scrollable canvas object that turtle creates and calls the resizable method on it. This is not documented, though - so it might produce unexpected behavior.
As a general remark: Whenever you want to use functionality of tkinter in a turtle program and you cannot find a turtle method for it - just check turtle's sources, figure out how turtle abstracts away the tkinter object (like the canvas in this case) and use the appropriate method on that object directly. Probably doesn't work all the time - but mostly you'll be able to achieve what you want.
Python turtle is built atop tkinter. When you run the turtle module standalone, it creates a tkinter window, layers it with a scrollable canvas and wraps in a screen object that provides lots of niceties for working with the turtle. But you can instead run the turtle module embedded i.e. build whatever kind of tkinter window you want and run turtle inside it.
Here's a very simple example of a window with a turtle drawing that's not resizeable:
from tkinter import *
from turtle import RawTurtle
root = Tk()
root.resizable(False, False)
canvas = Canvas(root)
canvas.pack()
turtle = RawTurtle(canvas)
turtle.circle(10)
root.mainloop()

Python tkinter keeping window on top when focusing on another window

I'm making a text editor, and I have made a find/replace function with it's own window.
It looks like this. I want it to become transparent when changing back to the main text window, but stay there. (Like what notepad++ does).
As you can see here, the find window is in front of the main window but it is transparent.
I already know I can use this to make the window transparent:
find_window.attributes('-alpha', 0.3)
But now I want it to stay on top while the focus is on the other window.
I have figured it out myself. I had to use the focus_out event and then use .lift() to place it on top:
def leave():
find_window.attributes('-alpha', 0.3)
find_window.lift()
find_window.bind('<FocusOut>', leave)

Close undecorated frames tkinter python

I am making a UI using tkinter in python. I want to make a full screen window for my UI, without any titles or border like an undecorated frame in Java. As described on http://effbot.org/tkinterbook/wm.htm I used
root.overrideredirect(True)
It works fine and I have an full screen window, but I can't close this window using normal close operation like ALt+F4 unlike undecorated frames in Java. I need to add a functionality to close my overrideredirect window using keyboard Alt+F4 keys. How can I do that?
If not possible to add that functionality, can I use an another way to make a full screen window using any other command such that I have close with Alt+F4 keys functionality
For me Alt+F4 works fine for an undecorated window, so i'm not sure what's going wrong for you.
That being said, you can of course make a button which destroys the window. This is probably best any way, since not everyone is familiar with (simple) keyboard shortcuts.
self.button_quit = Tk.Button(self.root, text='Quit', command=self.quit).pack
def quit(self):
self.root.destroy()

Categories

Resources