如何在pythonnet winforms字体中使用自定义构造函数?

时间:2016-12-28 09:36:15

标签: c# python winforms python.net

我正在使用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:没有构造函数匹配给定的参数

是否需要特殊规定?

1 个答案:

答案 0 :(得分:1)

尝试Font("Serif", 10.0) - 接受浮点数,但不接受整数。 pythonnet不支持隐式转换。