如何在 pythonnet winforms 字体中使用自定义构造函数?
How to use custom constructor in pythonnet winforms font?
我正在使用 pythonnet 在 python 上尝试简单的 winform 应用程序。
但我没办法把这件事做对。
import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Windows.Forms import Application, Form, Label
from System.Drawing import Size, Point, Font
text = """some large text"""
class IForm(Form):
def __init__(self):
self.Text = "You know I'm No Good"
font = Font("Serif", 10)
lyrics = Label()
lyrics.Parent = self
lyrics.Text = text
lyrics.Font = font
lyrics.Location = Point(10, 10)
lyrics.Size = Size(290, 290)
self.CenterToScreen()
Application.Run(IForm())
font = Font("Serif", 10)
TypeError: no constructor matches given arguments
是否需要特别规定?
尝试 Font("Serif", 10.0)
- 接受浮点数,但不接受整数。 pythonnet不支持隐式转换。
我正在使用 pythonnet 在 python 上尝试简单的 winform 应用程序。 但我没办法把这件事做对。
import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Windows.Forms import Application, Form, Label
from System.Drawing import Size, Point, Font
text = """some large text"""
class IForm(Form):
def __init__(self):
self.Text = "You know I'm No Good"
font = Font("Serif", 10)
lyrics = Label()
lyrics.Parent = self
lyrics.Text = text
lyrics.Font = font
lyrics.Location = Point(10, 10)
lyrics.Size = Size(290, 290)
self.CenterToScreen()
Application.Run(IForm())
font = Font("Serif", 10)
TypeError: no constructor matches given arguments
是否需要特别规定?
尝试 Font("Serif", 10.0)
- 接受浮点数,但不接受整数。 pythonnet不支持隐式转换。