Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
枕头,Tkinter,Python,不可见图像按钮_Python_Image_Button_Tkinter_Pillow - Fatal编程技术网

枕头,Tkinter,Python,不可见图像按钮

枕头,Tkinter,Python,不可见图像按钮,python,image,button,tkinter,pillow,Python,Image,Button,Tkinter,Pillow,大家晚上好:) 所以,我一直在做我的一个小项目,我想出了这个代码(在Sapphire64的帮助下:) 我可以将图像显示为按钮,使其可点击,但我的问题是,你可以看到它是一个按钮,你可以看到图像周围的矩形按钮框。 我希望图像可以像按钮一样点击,但本质上是不可见的。 然后我试着把它做成一个检查按钮,它的工作原理基本相同,但我又一次看到了一些东西的证据,而不仅仅是图像,检查按钮。我能不能让这个按钮隐形 所以我的问题是,我如何制作一个可点击的图像而不让它变得明显呢?它是一个按钮/检查按钮 谢谢 我把我的全

大家晚上好:)

所以,我一直在做我的一个小项目,我想出了这个代码(在Sapphire64的帮助下:) 我可以将图像显示为按钮,使其可点击,但我的问题是,你可以看到它是一个按钮,你可以看到图像周围的矩形按钮框。 我希望图像可以像按钮一样点击,但本质上是不可见的。 然后我试着把它做成一个检查按钮,它的工作原理基本相同,但我又一次看到了一些东西的证据,而不仅仅是图像,检查按钮。我能不能让这个按钮隐形

所以我的问题是,我如何制作一个可点击的图像而不让它变得明显呢?它是一个按钮/检查按钮

谢谢

我把我的全部代码放在这里,你可以看到图像显示为两个按钮,一个被注释掉了

from tkinter import *
from PIL import Image, ImageTk

SWH = Tk() #Create Window

SWH.geometry("1024x950+130+0")
SWH.title("ServiceWhiz.")

img = None  #Var for future image named img. Currently giving it "None" as value.

def printimage():   #When print image is pressed do this:
    global img      #Make reference to predefined var.
    load = Image.open("ServiceWhiz.png")   #Load Image from file.
    render = ImageTk.PhotoImage(load)   #Load the image.

################################
    img = Checkbutton(SWH,state = ACTIVE,height = 45,width = 289,offvalue=0, image=render,command=imgpress)    #Display the image as a button and allow it to go to imgpress.
    #img = Button(SWH,image=render,command=imgpress)
################################
    img.image = render  
    img.place(x=0,y=0)
    return;

def imgpress():
    global img
    img.destroy()
    Label1 = Label(SWH, text="Image has been clicked",fg="#0094FF",font=('Arial',20)).pack()
    return;

SWTitle = Label(SWH, text="ServiceWhiz.",fg="#0094FF",font=('Arial',20)).pack()
MyButtonTest = Button(SWH, text="Click Me.",fg="White",bg="#0094FF",command=printimage).pack()

如果您希望能够单击图像,只需将绑定添加到
。例如:

l = Label(..., image=render, ...)
...
def imgpress(event):
    ...
l.bind("<Button-1>", imgpress)
...
l=Label(…,image=render,…)
...
def imgpress(事件):
...
l、 绑定(“,imgpress)
...

通过将图像添加到画布并在画布上绑定,可以获得相同的效果

你可以做的是得到一个按钮的x和y坐标,点击看:然后你可以测试它们,看看它们是否在特定的边界内,如果是这样,它会做一些事情,这将有效地提供一个不可见的按钮。啊!这很有用,现在可以很好地工作了,非常感谢:)