how can i put photos without background as tkinter icon? - python

I am making a GUI using tkinter, I have some Button icons on my screen, that when user clicks, they execute their specific function. for example this one:
def screenshot():
# root.iconify()
myScreentshot=pyautogui.screenshot()
file_path=filedialog.asksaveasfilename(defaultextension='.png')
myScreentshot.save(file_path)
screenshot_image = tk.PhotoImage(file='images/app6.png')
screenshot = tk.Button(root,image=screenshot_image,bg='#0000CD',command=screenshot)
screenshot.place(x=640,y=500)
the problem is icons image. when I use the image as a button icon on my page, they always have a square or a rectangle on their background, although I use bg to set its color like my main page but I can still see it has a background.
How can I simply display the shape of the image without the background of the shape?

The square or rectangle is called the "relief". It is one of the visual cues that this is a button that can be pressed.
If you don't want that, set it to "flat":
screenshot = tk.Button(
root,
image=screenshot_image,
relief="flat",
bg='#0000CD',
command=screenshot
)
I would however advise you not to do this. The relief is there so that buttons are recognizable as such. Removing that in some places makes for an inconsistant user interface which can confuse new users.

Related

How to draw a square outside of the application window in python tkinter

Question: Is it possible to use python to draw a box anywhere on the screen, outside of the application window.
Background:
I have some mouse/keyboard macros I use for work, programmed in python pyautogui, and have to make new ones and adjust them frequently. I would like my program to be such that I can use my mouse to draw a box over any part of my screen over any application window, and record the coordinates of the box for use within my macros. The box would be used as the selector, and would disappear once recorded. Basically the same thing as when you hold down your left mouse button on your desktop to select multiple icons, except I would just need the coordinates of the box to be returned for use in the macros (which I can already do with pyautogui).
Is it possible to draw outside of the canvas window? Perhaps there is a way to hide the canvas window without hiding the contents within it?

Tkinter - How to remove the background of a widget?

I simply just want to have a button with an image (say an apple) and place it on my window without the background of the button.
Here is some sample code I've rushed:
from tkinter import *
root = Tk()
testbutton = Button(root, text="If this was an image I should be able to click the image only").pack()
root.mainloop()
This makes a button but it has a grey background that a. conflicts with my window background and b. allows users to click the image background.
I'm okay with the solution being windows specific however if there are mac and linux solutions as well i want those too.
I also dont want to use root.overridedirect(True) either.
Thanks in advance!

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)

wxpython transparent button

I am trying to design 650pxx100px button in an application.
The rectangle contains an icon on the left and a text on the right.
In order to make everything act like a button I was considering adding a transparent button on top of the text and icon but SetTransparent has no effect and adding a mask raises an exception as SetMask does not exists for BitmapButton.
bitmap = wx.EmptyBitmap(650, 100)
button = wx.BitmapButton(panel, -1, bitmap=bitmap, pos=(100, 0), size=(650, 100), style=0)
Has anyone done something like this successfully or can suggest a course of action that would help my case?
I have worked with GTK in the past and where there is an EventBox that can contain anything and have events bind to it.
wxPython doesn't really support that. Transparency is an all or nothing affair where either everything in your app is transparent or none of it is. You can do gradients if you use the PlateButton or the AquaButton though. Or you might be able to do something if you drew the button yourself.

Custom pyGTK button

I would like to create a button that I can control the look of the button using pyGTK. How would I go about doing this?
I would like to be able to point to a new image for each 'state' the button is in (i.e. Pressed, mouse over, normal...etc.)
As described in the API documentation for gtk.Image, "If you want to receive events on the image, such as button clicks, place the image inside a gtk.EventBox, then connect to the event signals on the event box.".
You probably want to use a gtk.Image rather than a gtk.Button, since buttons require more knowledge of how the theming engine works. If you really want to use a button, you'll need to read up on gtk rc files and the APIs for manipulating them.
Here's an easy way to use an image on a button. Note that there is no text given when you initialize the button (self.button1 = gtk.Button()). Adding text there would display the text instead of the image.
self.image1 = gtk.Image()
self.image1.set_from_file('images/home.png')
self.image1.show()
self.button1 = gtk.Button()
self.button1.add(self.image1)
self.button1.show()
self.backupHBox.pack_start(self.button1, True, True)
self.button1.connect("clicked", self.quit)

Categories

Resources