I am using wxpython version 2.9.4.0 and python 2.7.9.
I am trying the change the color of the text for a radio button.
I initialized by:
button = wx.RadioButton(panel, -1, 'Line', (200, 300))
I was able to change the color around the radio button by:
button.SetBackgroundColour((150, 150, 150))
But this is not the behavior I want. I want to change the color of the text, not the area around it. I expected that changing the foreground colour would change the text color of the radio button, as that is how the color is changed for static text (as shown here Change the colour of a StaticText, wxPython). The code I used for this is:
button.SetForegroundColour((0, 255, 0))
However, for reasons unknown to me, this did not change anything about the radio button.
Am I mistaken that this command should change the text color of the radio button, and if so, what is the proper command?
Thanks in advance!
The SetForegroundColoour and SetBackgroundColour methods are not guaranteed to work. The reason is that wxPython uses the native widgets for the OS it is running on. If the native widget does not support changing the text's color, then these methods will have no effect. Some widgets allow changes to color on Mac while the same widgets on Windows do not.
If you really need to change text color in a radio button, then you'll probably need to create a custom widget. See the following:
http://wiki.wxpython.org/CreatingCustomControls
Use a wx.RadioButton with no label
&
put a wxStaticText next to it
and set your foreground colour as u wish
Related
In other words, is it possible to create a button with Tkinter and place Tkinter canvas text on top of it? The normal workaround would be to simply create a label containing the text on top of the button. However, the button where I want to place the text is an image containing a color gradient and you need to specify a background color for the label.
In other words, how can I create an image that I can click on and execute a function (like a button would do) and place text on top of this button without the need of specifying a background color for the text?
Is there a way to place a tkinter button behind tkinter canvas text?
No, there is not. Windows will always be on top of other canvas objects.
From the official documentation:
"Window items are an exception to the above rules. The underlying window systems require them always to be drawn on top of other items. In addition, the stacking order of window items is not affected by any of the canvas widget commands; you must use the Tk raise command and lower command instead."
In other words, how can I create an image that I can click on and execute a function (like a button would do) and place text on top of this button without the need of specifying a background color for the text?
You can create your own button widget by placing the image on a canvas, then writing text on top of the image. You can then add your own bindings that fire when you click on the canvas.
This is an repost.
I am kind of new in QtDesigner and wanted to do something about the uglyness of just some buttons.
All i have done yesterday was looking on the internet on how to change the background color of a screen in Qt Designer. How to change the color of a button and how to make it flow into another color on the sides. Guess what.
I found nothing.
I hope that some of you die-hard coders know what i need..
EDIT 1: What i mean with a color flowing into another:
Here pink flows into purple, do you get what I mean?
To make the changes of colors you can use stylesheets, in Qt Designer you must follow the following steps:
Right click on the item you want to change and select: change stylesheet
Then press the button to the color side and select background-color, Then select the color and press the OK buttons.
Output:
plus+:
I want to add colorless icons to menu items. To look reasonably, the icons should have the same color as the text used in the menu. It works everywhere except Ubuntu. The problem is that the default Ubuntu Unity theme uses different colors for the main menu and for other text (e.g. popup menus) in the application. I need the color specifically used by the main menu.
QApplication.palette().color(QPalette.Text) returns the dark gray color used by text in the application. It's almost invisible on the dark gray menu background.
I tried the palette() method on a QMenu descendant, but it returns the same value as QApplication.palette().
It turns out QMainWindow.menuBar().palette() has colors matching the Unity menu on top of the screen (I just learned it's called appmenu). That makes it possible to use the same color as the menu text.
But there is a problem. The version of the icon for the QtIcon.Active mode is not used for the active menu item. That can be seen in the high contrast mode. The text color changes, but the icon color doesn't. The icon "disappears" when the menu item is selected. That's not good enough for a polished program.
I tried many workarounds, such as adding extra pixmaps to the icon with QIcon.addPixmap(). Nothing works. The appmenu operates in a separate process and doesn't want to our "Active" icon. So I'm going to draw real icons that look good on any reasonable background and don't need to change color with the widget.
Too bad. I expected that the QIcon mode and state were made specifically for such tasks.
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?
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.