How to use custom constructor in pythonnet winforms font?

817 views Asked by At

I am trying simple winform application on python using pythonnet. but I am not able to make this thing right.

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

Is there any special provision required?

1

There are 1 answers

0
den.run.ai On BEST ANSWER

Try Font("Serif", 10.0) - floats are accepted, but not integers. Implicit conversion is not supported in pythonnet.