gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 15:50:27 24 4
gpt4 key购买 nike

我正在使用 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) - 接受 float ,但不接受整数。 pythonnet 不支持隐式转换。

关于c# - 如何在 pythonnet winforms 字体中使用自定义构造函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41359196/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com