tkinter Button widget 'inside' another button widget-tkinter - python

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.

Related

how to make tkinter window not moveable with the mouse

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.

Why is tkinter Toplevel getting local focus grab, but not getting lifted on top of other window(s)

As the title describes, I am creating a Toplevel tkinter window, but after creation, there is about 300 milliseconds when it is acting normal, but then the main window comes on top of it, blocking out half of it, without taking the focus away from the Toplevel window. Example:
This is manually fixed by bringing the main window into focus, and then clicking back on the Toplevel widget, however is a great inconvenience, as the Toplevel is a notification window, so clicking away from it will destroy it. I have tried using the set_grab() command, however it prevents the main window from coming into focus, disabling the manual solution. The lift() command extends the period in which the Toplevel is in focus, however it still gets pushed into the background within one tick of the mainloop. I also tried focusing the main window with focus() and then focusing the Toplevel, as per the manual solution, but to no avail, as this scenario always arrived, regardless of what I tried.
Why is this happening, and how could I fix it?
MRE:
import tkinter as tk
class Notify(tk.Toplevel):
def __init__(self, master, title, message, time, **messageArgs):
super().__init__(master=master)
self.title(title)
self.message = tk.Label(self, text=message, **messageArgs)
self.message.pack(anchor='center')
self.after(time, self.close)
self.lift() # The most successful one yet, but still does not solve the issue
def close(self):
self.master.focus()
self.destroy()
root = tk.Tk()
Notify(root, 'Blah Blah Blah', 'Spam Spam Spam', 5000)
tk.mainloop()
This answer here: https://stackoverflow.com/a/31927283/12692182 will solve your problem. You need to specify what widgets it is supposed to be on top of in lift():
self.lift(aboveThis=self.master)
instead of:
self.lift()
Note: this was my own answer that I shared to help out others with a similar problem. I still would like help understanding why it works, as well

How do I stop a disabled tkinter button from being greyed out?

Basically, I've got a tkinter button with an image on it, and when I disable the button it greys out a square around the image and looks pretty bad. Is there any way to stop this from happening while keeping the button disabled?
Instead of disabling the button, you can unbind the callback:
button['command']=0

How to show a highlighted label when The mouse is on widget

I need to know how to make a highlighted label(or small box )appears when the mouse is on widget like when you are using browser and put the mouse on (reload/back/etc...) button a small box will appear and tell you what this button do
and i want that for any widget not only widgets on toolbar
As the comment of #ekhumoro says
setToolTip is the solution

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.

Categories

Resources