Trying to add an image widget to GridLayout but I am receiving a not callable error. I have reviewed samples online but seems to be causing error for me. I'm sure its something simple but I am new to kivy and Python.
faceImage = Image(source='Event_Faces/David_Johns.jpg')
self.inside2.add_widget(faceImage)
ERROR:
File "C:/Users/thoma/PycharmProjects/FacesApp/Main.py", line 62, in __init__
faceImage = Image(source='Event_Faces/David_Johns.jpg')
TypeError: 'module' object is not callable
I discovered the issue was related to me importing Pil Image and kivy Image and that was causing conflict.
Related
I'm trying to set the font family of QtwebEngine by referring to the official document.
However, when I ran the code below, I've got an error message.
from PySide6.QtWebEngineCore import *
QWebEngineSettings.setFontFamily(QWebEngineSettings.StandardFont, "Arial")
TypeError: descriptor 'setFontFamily' for 'PySide6.QtWebEngineCore.QWebEngineSettings' objects doesn't apply to a 'PySide6.QtWebEngineCore.QWebEngineSettings.FontFamily' object
What should I change to handle this error?
I want to open image in python.I have been using PIL for opening the image but it throw 'module' error is not callable
import PIL
from PIL import Image
image=Image.open(r'C:\Users\intel\Downloads\11fcf12ff3cf97e8e7a88f3e485255e6.jpg')
print(image)
display(image) #the error is thrown here
Are you sure you want to use display? What would you like accomplished? Maybe show... There is a method like show() in PIL library so in your case it would be image.show()
i am trying to use Tkinter on python 3.6
However it gives me an error when i try to run the following code:
import tkinter
top = tkinter.Tk()
top.mainloop()
The error says:
AttributeError: module 'tkinter' has no attribute 'Tk'
I receive the same error if i try to call the attribute Frame.
Any idea?
Thanks
Make sure you didn't name the file tkinter.py; It prevents import of tkinter module because the file your wrote searched first and imported.
Rename the file, and also make sure there's no tkinter.pyc remained.
I feel like this should be pretty simple, but I guess I am missing something.
So I want to set the icon of a window with one of the stock images. I have tried:
windowIcon = gtk.image_new_form_stock(gtk.STOCK_DIALOG_AUTHENTICATION, gtk.ICON_SIZE_MENU)
window.set_icon(windowIcon.get_pixbuf())
Python then complains that:
File "./sample.py", line 44, in init
window.set_icon(windowIcon.get_pixbuf())
ValueError: image should be a GdkPixbuf or empty
I try to convert the gtkImage to a GdkPixbuf because when I didn't python complained that
TypeError: icon should be a GdkPixbuf or None
In the pygtk documentation it says:
If the storage type of the image is not either gtk.IMAGE_EMPTY or gtk.IMAGE_PIXBUF the ValueError exception will be raised.
So I guessing that storage type of the stock image is wrong. The question is how to I get around this?
You can use the .render_icon() method on any GtkWidget to provide a stock item as the icon.
windowicon = window.render_icon(gtk.STOCK_DIALOG_AUTHENTICATION, gtk.ICON_SIZE_MENU)
window.set_icon(windowicon)
The render_icon() method works as given above. Your code was having problems, because the get_pixbuf() method was returning None. This is because the image was not created from a pixbuf, and for some reason, it won't convert it. Another way of getting a pixbuf from an image is to use the gtk.gdk.pixbuf_new_from_image() function.
I'm missing something at a very basic level when it comes to loading an image using PIL and displaying it in a window created by Tkinter. The simplest form of what I'm trying to do is:
import Tkinter as TK
from PIL import Image, ImageTk
im = Image.open("C:\\tinycat.jpg")
tkIm = ImageTk.PhotoImage(im)
tkIm.pack()
TK.mainloop()
When I try to run the code above, I get the following:
RuntimeError: Too early to create image
Exception AttributeError: "PhotoImage instance has no attribute
'_PhotoImage__photo'" in <bound method PhotoImage.__del__ of
<PIL.ImageTk.PhotoImage instance at 0x00C00030>> ignored
I've confirmed the file is present and can be opened in an image editor and also that it can be displayed using im.show(). What am I missing?
Tkinter has to be instantiated before you call ImageTk.PhotoImage():
TK.Tk()
It's very true what Meredith said you need to add that line for sure!
I would like to show you my image formatting and then compare it to yours and see if there any different, my code for a image is
master.image = PhotoImage(file="Banditlogo.gif")
w = Label(master, image=master.image)
w.photo = master
w.pack()
And your code is
im = Image.open("C:\\tinycat.jpg")
tkIm = ImageTk.PhotoImage(im)
tkIm.pack()
We are both using PIL with PhotoImage
I can't help wondering are both ways correct?
At this point in time I don't have enough knowledge to fully answer your PIL question but it is interesting to compare both codes as they are different. I can only suggest doing what I do when it comes to example codes people share with me, and that is "if mine don't work, try the example code and see if that fixes the code" when I find something that works I stick with it.
Would someone with more understanding of Tkinter please explane the workings of, How do I use PIL with Tkinter?
Knowledge is power so please share.