如何确定在ironpython中导入哪些windows窗体模块



我正试图从本页中包含的示例中复制一些代码,并使用这些教程中的一些帮助将其修改为在iron python上运行。但当我走出教程时,我不知道我需要导入什么模块。

目前我有以下代码

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的iron-python脚本引擎中运行。我从其他地方用一些文本(如information('Important Announcement'))调用information()函数。)

因此,一旦我尝试执行这个self.flowPanel = FlowLayoutPanel(),代码就会中止。如果我注释掉flowPanel行,窗口窗体将正常显示。

所以在我看来,我还没有正确导入所需的模块。不幸的是,我不知道该加载什么。我试着装载我认为合适的东西,但似乎都不适合我

如何确定从System.Windows.Forms导入哪个模块以便在代码中创建FlowLayoutPanel?一般来说,如何确定要导入什么才能获得相关功能?

答案似乎是第三个点"后面的任何内容在系统中。Windows。表单

所以使用系统。Windows。表格。表单,您需要导入表单。

所有答案都错了。导入中缺少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')    

相关内容

  • 没有找到相关文章

最新更新