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?
Related
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.
After reading through much of the Pillow documentation, stack overflow, and the web, I have been unable to decipher this error message that is throwing off my application. My current setup:
Python 3.7.6
Pillow 7.0.0 [Docs]
Below is a verifiable example of what I have been working on. Essentially, my error happens when I use title_font in place of where I use default_font. Emphasized by the 2 comments stating: # TODO Aborts with error unless using default_font TODO.
from PIL import ImageFont, ImageDraw, Image
def app():
# Default Font with static size and font type
default_font = ImageFont.load_default()
# TODO Title Font that is the desired use
title_font = ImageFont.truetype(font="~/Library/Fonts/Verdana.ttf", size=36)
# Background Image to draw text on
bg_img = Image.new(mode = "RGBA",size = (3480,2160), color="Green")
# Creates an object that can be used to draw in the given image.
d = ImageDraw.Draw(bg_img)
txt = "Hello World"
# TODO: Aborts with error unless using default_font TODO
# Returns (width, height) of text in pixels with designated font
txt_width, txt_height = default_font.getsize(txt)
print(f"Text Width:{txt_width} Text Height: {txt_height}")
# TODO: Aborts with error unless using default_font TODO
# Draws "Hello World" onto background image
d.text((10,60), text=txt, font=default_font, fill=(255,255,255,255))
# Pop Up window
bg_img.show()
Below is the error message that I get back from both ImageDraw/ImageFont methods:
>>> app()
dyld: lazy symbol binding failed: Symbol not found: _hb_language_get_default
Referenced from: /usr/local/lib/libraqm.dylib
Expected in: flat namespace
dyld: Symbol not found: _hb_language_get_default
Referenced from: /usr/local/lib/libraqm.dylib
Expected in: flat namespace
I have already tried:
To change the path used for the custom font and to change to another font loading method (i.e. ImageFont.load(filename), ImageFont.load_path(filename).
To settle with ImageFont.load_default() but as you might be able to tell by running it, the default font is very small and there is no way of changing its size or style.
One last thing that I was not sure about was this line in the installation guide that recommended after brew install of the packages Pillow depends on:
Then see depends/install_raqm_cmake.sh to install libraqm.
Can be found here halfway through the Building on macOS section. I have a nagging feeling this could be the cause but I simply do not understand what action it wants me to take.
Long time lurker, first time poster. Thank you for any help now and all the help afforded to me over the years!
UPDATE: Used my example on another MacBook and it works fine. I am going to reset the one it wasn't working on and build from scratch. Thanks for all your assistance!
I assume you used (like me) a Mac with OS Catalina or similar, and might have installed the mentioned library with "$ brew install libraqm" too.
I resolved it by changing the layout_engine, and due to this, not using 'libraqm' for PIL layout work in the background.
font = ImageFont.truetype(
"/System/Library/Fonts/Keyboard.ttf", layout_engine=ImageFont.LAYOUT_BASIC, encoding=self.encoding, self.font_size,)
If you do this you might not be able to use Chinese or similar Fonts. I am not sure where, in 'brew', 'pyenv' or 'libraqm' is the issue but I try to find it out.
how could i dynamically change the icon of a button created with glade?
______________________ Last Edit _________________________________________
I'm trying this:
self.button_waiting=self.builder.get_object('button_waiting')
image=Gtk.Image()
image.set_from_stock(Gtk.STOCK_DIALOG_ERROR, Gtk.IconSize.BUTTON)
image.show()
self.button_waiting.remove(image)
self.button_waiting.add(image)
I get this error:
Gtk-CRITICAL **: gtk_container_remove: assertion `gtk_widget_get_parent (widget)
== GTK_WIDGET (container) || GTK_IS_ASSISTANT (container)' failed
(fresh_install:16299): Gtk-WARNING **: Attempting to add a widget with type
GtkImage to a GtkButton, but as a GtkBin subclass a GtkButton can only contain
one widget at a time; it already contains a widget of type GtkLabel
it seems like the error of the answer that I'm copying, but doing what he did is not working for me.
I read that it is possible to put images on labels, how can i get the name of the label of the button made in glade?
following this answer:
replace image using gtk.image.set_from_file
___________________ Original Question _________________________________
I'm trying this:
self.button_waiting=self.builder.get_object('button_waiting')
self.button_waiting.set_label("Cancel")
image=Gtk.Image.set_from_stock(Gtk.STOCK_DIALOG_ERROR, Gtk.ICON_SIZE_BUTTON)
image.show()
self.button_waiting.image.clear()
self.button_waiting.add(image)
I get the following error:
AttributeError: 'gi.repository.Gtk' object has no attribute 'ICON_SIZE_BUTTON'
But i found GTK_ICON_SIZE_BUTTON on the reference manual >.<
I'm going to assume that you are using PyGObject (GTK+ 3.x) based on the fact that you're Gtk instead of gtk. If that's the case, then you should use Gtk.IconSize.BUTTON rather than Gtk.ICON_SIZE_BUTTON.
This is because the GObject Introspection will put the constants into a namespace rather than the long constants we see in the C source code. It's generally pretty easy to figure it out based on the context.
I'm using Python 3 and QT4 with pyqt. I've been unable to access data from qcomboboxes and qplaintextedits.
I've read the documentation here:
http://doc.qt.io/qt-4.8/qcombobox.html
http://doc.qt.io/qt-4.8/qplaintextedit.html
The only thing on these pages that appears to describe how to pull the selected value are 'plainText' for the plain text box and 'currentText'for the combo box. These aren't explicitly described as the solution, but they're the only thing I found that makes sense.
currentText returns the following error: "AttributeError: 'QPlainTextEdit' object has no attribute 'plainText' "
currentText does not return an error, but returns the starting value of the combo box, regardless of what's selected.
Example code I'm using:
x = window.ui.tb_x.plainText()
y = window.ui.cb_y.currentText()
Any ideas?
Its toPlainText() method in qplaintextedit.
And try itemData( combo.currentIndex ) for combo.
I'm using Tkinter for the GUI, and I have one problem:
I try to make a message widget, and when I write:
body = Message(top, bd = 2)
body.pack(side=RIGHT)
I get this error:
body.pack(side=RIGHT)
AttributeError: Message instance has no attribute 'pack'
I dont understand this becaue I checked in some guides and Its allowed to use 'message' this way, as seen here in the example: http://www.tutorialspoint.com/python/tk_message.htm
Is there another way to write this?
There are at least two Message classes in Tkinter. One of them comes from tkMessageBox.Message, and the other one is from Tkinter.Message. The former is a subclass of the Dialog from tkCommonDialog, and since packing a dialog is meaningless, there is no pack method for this case. The later is a Tk widget called message, which is the one you want; being a widget, it makes sense to pack it.
Your complete code mostly like have something in the form (Python 2):
from Tkinter import *
from tkMessageBox import *
The second import shadows the Message class from the first import. To use the Message class you are after, simply change the above code to:
from Tkinter import *
import tkMessageBox
Then adapt your code accordingly.