我正在尝试复制包含in this page的示例中的一些代码,并将其修改为在铁python using some help from these tutorials上运行。但是当我走出教程时,我感到困惑,我不知道我需要导入哪些模块。
目前我有以下代码
import clr
clr.AddReference("System.Drawing")
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import Application, Form, Button, Label, DockStyle, AnchorStyles, Panel, Screen, FlowLayoutPanel
class OKWindow(Form):
def __init__(self,InfoTXT):
newlines = 0
screenSize = Screen.GetWorkingArea(self)
STRwidth = 200
STRheight = 30
FORMheight = 160
FORMwidth = 300
self.Text = 'Information'
self.Height = FORMheight
self.Width = FORMwidth
self.flowPanel = FlowLayoutPanel()
#self.flowPanel.AutoSize = true
#self.flowPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink
self.Controls.Add(flowPanel)
label = Label()
label.Text = InfoTXT
label.Top = 30
label.Left = 50
label.Height = STRheight
label.Width = STRwidth
button = Button()
button.Text = "OK"
button.Width = 100
button.Top = FORMheight - 80
button.Left = (FORMwidth / 2) - 50
print button.Anchor
button.Anchor = AnchorStyles.Bottom
button.Click += self.buttonPressed
self.Controls.Add(label)
self.Controls.Add(button)
def buttonPressed(self, sender, args):
Application.Exit()
def information(Message):
Application.EnableVisualStyles()
form = OKWindow(Message)
Application.Run(form)
(注意:代码并不精确,因为它目前在OCTGN的铁python脚本引擎中运行。我从其他地方调用了info()函数,其中包含information('Important Announcement')
等文本。)
因此,一旦我尝试执行此self.flowPanel = FlowLayoutPanel()
,代码就会中止。如果我注释掉flowPanel行,则窗体正常显示。
所以在我看来,我没有正确导入所需的模块。不幸的是我不知道要加载什么。我尝试加载我认为合适的任何东西,但似乎没有一个适合我。
如何在System.Windows.Forms
中找出要导入的模块,以便在我的代码中创建FlowLayoutPanel?一般来说,如何确定要导入的内容以获得相关功能?
答案 0 :(得分:1)
答案似乎是它是在第三个点之后的任何东西'。'在System.Windows.Forms
中因此,要使用System.Windows.Forms.Form,您需要导入Form。
答案 1 :(得分:0)
所有答案都错了。 导入中缺少AutoSizeMode,则代码有效
import clr
clr.AddReference("System.Drawing")
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import Application, Form, Button, Label, DockStyle, AnchorStyles, Panel, Screen, FlowLayoutPanel,AutoSizeMode
#from System.Windows.Forms import *
class OKWindow(Form):
def __init__(self,InfoTXT):
newlines = 0
screenSize = Screen.GetWorkingArea(self)
STRwidth = 200
STRheight = 30
FORMheight = 160
FORMwidth = 300
self.Text = 'Information'
self.Height = FORMheight
self.Width = FORMwidth
flowPanel = FlowLayoutPanel()
flowPanel.AutoSize = True
flowPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink
print(AutoSizeMode)
self.Controls.Add(flowPanel)
label = Label()
label.Text = InfoTXT
label.Top = 30
label.Left = 50
label.Height = STRheight
label.Width = STRwidth
button = Button()
button.Text = "OK"
button.Width = 100
button.Top = FORMheight - 80
button.Left = (FORMwidth / 2) - 50
#print( button.Anchor)
button.Anchor = AnchorStyles.Bottom
button.Click += self.buttonPressed
self.Controls.Add(label)
self.Controls.Add(button)
def buttonPressed(self, sender, args):
Application.Exit()
def information(Message):
Application.EnableVisualStyles()
form = OKWindow(Message)
Application.Run(form)
information('laber')