Does Tkinter or underlying Tk framework support the ability to apply the equivalent of the attributes() method to Frames vs. Windows?
Specifically: I have forms with a message area that I would like to fade away in jquery-like manner, eg. display a non-modal status message that fades away. I know I can fade a Tkinter window via window.attributes("-alpha", alpha), but I don't see an equivalent way to achieve this effect with a Frame. (I know I could place a top-level message window over my dialog, but coordinating the position and size of this window to match the layout of my dialog sounds complicated).
No, there is no way to do what you want. Tkinter only supports transparency on top-level windows.
Related
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.
I wanted to ask if it is possible to draw a child window inside a parent window so that it will only be able to move inside the parent window and won't be able to move out of the parent window bounds.
If you mean having actual windows with title bar, menu, status bar etc. inside the parent window then the answer is:
No, Tcl/Tk and by extension Tkinter does not support this with its standard widgets.
There have been efforts in the past to implement widgets which emulate MDI as you can see on the TCL wiki, but most of them are over a decade old. You will probably have to implement it yourself or choose a different GUI toolkit if you really need to implement this kind of UI design.
If you do it yourself, you can use the Frame widget as the subwindow, and use place to put it in the containing window. Or, you can create it as an object on a canvas. You'll have to write all of the code to give the inner window borders and a title bar, and to manage moving it around, iconifying it, etc.
Is there a python library that allows you to create a GUI without the window manager (and equivalent under MS Windows) frame thing, and allow to set the window top-most (like over all other windows) ?
I've been looking on Internet but I'm obviously missing the right keywords.
Yup. Tkinter, or "tkinter" in python3. It's included in standard python distributions
Removing the Window Manager
The method
root.overrideredirect(True)
Removes the borders and manager. Setting the flag indicates to the manager that you don't want the widget to be managed. You can look at ttk, an extension to tkinter commonly included (in Python3 it's tkinter.ttk) if you don't want to completely remove the border, but just pick a different style.
Setting the TopMost Attribute
The method
root.wm_attributes("-topmost", 1)
Will put it at the top of the screen Combined, these will give you the desired behavior. You can then use other tkinter frames to decorate the widget as you please, i.e., add custom borders or close/minus buttons that would normally be included in the manager.
Resources
See this, e.g. for applying the topmost attribute
Make a tkinter window appear over all other windows
From Effbot about "overridedirect" (http://effbot.org/tkinterbook/wm.htm):
Sets or gets the override redirect flag. If non-zero, this prevents
the window manager from decorating the window. In other words, the
window will not have a title or a border, and it cannot be moved or
closed via ordinary means.
Note:
These functions can only be applied to the root window (Tk instance) or another Toplevel instance.
I created a analog rpm gauge using the canvas widget of Tkinter and I want to import it in a wx GUI application (as a panel, maybe). Is there any way to do it or I must rewrite this widget in wx?
There is no (simple) way to do that - WxWidgets is an abstraction over different toolkits in different systems, and use different mainloop functions, while Tkinter has its own mainloop - that is to start with.
So making that work would at leas require:
that you'd setup different threads able to run both mainloops in
paralell,
finding a way to get Tkinter to render the widget to an
in memory bitmap
create a custom widget in wx which would render
that bitmap to the screen
and map events on it back to Tkinter, if
it is supposed to respond events
So you are definitely better of writting the widget again.
WxPython has a speed meter widget just use that instead.
import wx.lib.agw.speedmeter
You would have to rewrite the widget in wxPython or find a widget that does the same thing that's already included with wx. Tkinter is a completely different GUI toolkit that draws its own widgets and is based on TCL whereas wxPython is a wrapper around wxWidgets which is based on C++. There is no easy way to embed a widget from Tkinter into wxPython.
As Yoriz mentioned, you might be able to use the speedmeter widget in wxPython. Check out the wxPython demo package as it will show you how to use that widget and most of wxPython's other widgets. Hopefully you can find something that's already included. Otherwise, you may want to take a look at the following page:
http://wiki.wxpython.org/CreatingCustomControls
Is there any way to get a border like this in Tkinter? Notice how it lacks the buttons on the top right. Also I don't want this program to show in the task bar.
This is in windows 7, btw.
Tk (and thus, Tkinter) has a command for removing all window manager decoration. This command in tkinter is the "wm_overrideredirect" method of toplevel windows. Pass it a parameter of True to remove the window manager decorations. You can then draw whatever borders you want, usually by packing a canvas over the entire window and drawing on the canvas.
However, when I experiment with this on my Mac, the window appears properly but won't take focus. Perhaps this is a bug in Tkinter. I don't see the same problem with identical code in Tcl.
The WS_DLGFRAME window style should give you a window without a titlebar and WS_EX_TOOLWINDOW is normally also used for a window like this so it is not visible in the taskbar (Or with a hidden parent window like control panel dialogs before Vista) You can figure out the exact window styles with a tool like Spy++ (Visual Studio) or WinSpy++