I'm trying to add a tooltip to an image. Following a PyGTK tutorial it seems that this should work:
image = gtk.Image()
image.set_from_file(image_path)
box.pack_start(image, expand=False)
tooltip = gtk.Tooltips()
tooltip.set_tip(image, "Hello!")
Except it doesn't. Nothing happens when I mouse over the image. However, I know that works with buttons (I ran the sample code from the tutorial).
With GTK 2.12 and above, I could probably just use image.set_tooltip_text("Hello!") but I'm stuck at 2.10.4 and have to use gtk.Tooltips.
Edit
According to the documentation for gtk.Tooltips:
Tooltips can only be set on widgets which have their own X window. To check if a widget has its own window use widget.flags()>k.NO_WINDOW. To add a tooltip to a widget that doesn't have its own window, place the widget inside a gtk.EventBox and add a tooltip to the eventbox instead.
So that solves my problem but leaves me a bit confused. I checked the flags for a button and it has the same gtk.NO_WINDOW flag that images have. So why don't buttons need an EventBox but images do?
To satisfy its interface, GktButton creates an event box (well, something like an event box) for itself, internally. I.e. it captures events in a non-visible gdk window. GtkImage doesn't have a similar interface to satisfy so it doesn't need to capture events.
Perhaps it's an accident of the button's internal implementation that using the tooltip interface works without embedding a button in an EventBox or perhaps the tooltip interface actually depends upon a gdk window whether it's visible or not and the Widget interface lacks that sort of flag.
Related
I'm having a problem with changing the background of this part of the window:
How do I change it?
As I see you are using windows.
This color is set by the theme you are currently using. It is the same for every window.
So I cross out the possibility of only using the Tkinter module for this.
Tkinter is responsible for what is in the window but the window manager decides about the border. For example in Ubuntu the window would look totally different.
I guess, you would need some windows specific calls for that.
You can remove the border with root.overrideredirect(1) if I remember correctly.
PS: put "windows" into the tags of this question.
How would I go about making a overlay widget with qt?
I've considered using a QPaintEvent or a QGraphicsScene, but I want to be able to add widgets and for the widget to not occupy space in a layout, causing other widgets to shift when the popup appears.
I believe the best solution is to parent the so called overlay widget to the window or even have the overlay widget be in its own window.
The first solution might be easier to do, but the overlay widget is bound to the inside of the window.
If you go with the second solution, you will have to play with the windows flags to make it borderless.
In both cases, you may have to use the raise() function to make sure your overlay widget is on top.
Discussing "using a QPaintEvent or a QGraphicsScene" is off-topic. How you draw the widget does not impact how the widget will interact with the widget stack.
If you want an example, you can take a look at the code of QCompleter which does something similar. In particular look for QCompleter::setPopup() and QCompleterPrivate::showPopup().
I have search far and wide on how you can paint the background color of a button or GenButton with a pattern such as lines or cross hatch. I have seen examples of wx DirectContext so that you can draw objects with patterns instead of just solid colors but it seems that this is only for specific shapes and not the color of button objects. Does the dc or gc library allow to paint on these objects. I know that I have to create an event handler for OnPaint and OnResize but I may be missing some steps so that it applies this to the button itself.
The wxPython package uses native widgets in its core widgets as much as possible. Thus, the wx.Button widget is going to be a native widget that you can only modify via the methods mentioned in the documentation. As Igor mentioned, you can try using SetBackgroundColour() or SetForegroundColour(), although depending on your platform's button widget, they may or may not work.
What you really want is a custom widget. I recommend checking out the GenericButtons, PlateButton and GradientButton for examples. You might even be able to use a GenericButton directly and paint its background as you mentioned.
wx.Button object represents a native control. And so unfortunately you can't manipulate how the native control paints itself.
You can try SetBackgroundColour()/SetForegroundColour() but this is as far as you can go.
I'm working on a X-plotter like widget that plots incomming data live.
I already searched for an solution to realize a scrolling along the x-axis if the widget has to much values and so they don't fit.
I had the folling approaches to realize it:
derive from a widget that supports scrolling and child widgets and add my own widget while making it bigger and bigger during the live updates: -> Which parent do I need to use and how do I avoid to draw all the stuff that is currently not visible?
modify my widget in a way that it supports the scrollbars itself -> but how?
draw/handle my own scrollbars -> worstcase :(
I really searched the web for suggestions or examples, but there is nothing about how to "construct" custom controls in a good way (beyond drawing something) esp. in the case of interaction...
Sorry but I'm a newbie at GTK in general :/
Most widgets in Gtk do not have scrollbars.
If you want to scroll the entire widget, you have to implement the GtkScrollable interface. Then, you add the widget to a GtkScrolledWindow. The scrolled window has the scrollbars, those GtkScrollbars are linked with GtkAdjustments which are passed to your custom widget through the GtkScrollable interface set_vadjustment and set_hadjustment.
If you just want to add a scrollbar and control its behaviour yourself, then you need to somehow add a GtkScrollbar in your widget, which means you will need to make it a container too.
The GtkScrollable approach is the following, first you implement vadjustment and hadjustment setters and getters, then when the GtkAdjustments are set, you set its lower and upper limits and the page size(how much of the widget is visible at once). After that, you connect their value-changed signal so you can refresh your widget when the scrollbars are dragged. A GtkScrollable doesn't get to check the scrollbars, only the adjustments that will be bound to the scrollbars. When drawing the widget you get the adjustments' value property in order to determine how much the scrollbars have shifted in the horizontal and vertical axes.
I am trying to remove the border that is coming with the buttons in my program.
I've tried adding bd=0 and highlightthickness=0 to the Button() but it's just not working.
Can anyone suggest how to do this?
Current code example:
self.highscore_button_image = ImageTk.PhotoImage(file="images/buttons/highscore.png")
highscore_button = Button(self.menu_window, bd=0, highlightthickness=0, image=self.highscore_button_image)
highscore_button.place(x=266, y=273)
Buttons: I want to remove the white border... It also comes with a regular button without an image
Python version: 2.7.1
OS: Mac OSX Lion
Using Tkinter at the moment...
I'm not sure you can get rid of that border for a button. You could use a Label widget instead of a Button widget, and bind mouse events to it if it needs to be clickable. The Label widget doesn't have that button-y outline.
highscore_button = Button(....,relief=FLAT)
The relief style of a widget refers to certain simulated 3-D effects around the outside of the widget, it can be RAISED, SUNKEN,FLAT,GROOVE,RIDGE.
Removing border on buttons on Mac is currently not allowed. OS X is quite strict at this, there is no way to remove the border if using tkinter. I recently just had the same problem and all the methods I've tried are not working properly on Mac while most of them work on Windows.
However, it is possible to do it on Windows using "relief=FLAT" or "highlightthickness=0". You can also use "padx=0, pady=0" to have a really thin border, it will still exist.
You can also check out this site which talks about styling tkinter widgets(not only buttons but all the widgets): http://effbot.org/tkinterbook/tkinter-widget-styling.htm
You may change the colour of the border(ButtonFace) to the same colour of your background according to this site.
There is a similar question on button styling here as well: How to change the foreground or background colour of a Tkinter Button on Mac OS X?