Workbench平台GUI二次开发入门系列——基本控件1
案例使用方法本入门教程中的所有案例均已测试通过,具体参考入门1中的使用方法。目录01 入门102 入门2 03 布局管理1 04 布局管理2 05 菜单栏1 06 菜单栏2 07 工具栏 08 基本控件1 09 基本控件2 10 基本控件3 11 基本控件4 12 高级控件1 13 高级控件2 14 对话框1 15 对话框2 16 拖拽功能 17 绘图1 18 绘图2 19 绘图3 20 绘图4 21 进度条 22 游戏——贪吃蛇基本控件1case14 工具栏控件1 Label目标:创建控件Label本案例中展示如何创建Label ,Label非常好用,用于已有的文字说明,标签等,其中的文字一般情况下无法实时变更。# encoding: utf-8import sysimport clrclr.AddReference("System.Windows.Forms")clr.AddReference("System.Drawing")from System.Windows.Forms import Application, Form, Labelfrom System.Drawing import Size, Point, Fonttext = """Meet you downstairs in the bar and heardYour rolled up sleeves and your skull t-shirtYou say why did you do it with him today?And sniffed me out like I was tanquerayCause you're my fella, my guyHand me your stella and flyBy the time I'm out the doorYou tear me down like roger mooreI cheated myselfLike I knew I wouldI told ya, I was troubleYou know that I'm no goodUpstairs in bed, with my ex boyHe's in a place, but I cant get joyThinking of you in the final throws, this is when my buzzer goes"""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()) 效果展示:case15 工具栏控件2 CheckBox目标:创建CheckBox (复选框)本案例中展示如何创建CheckBox,该控件可用于是否考虑某种条件的情景,非常实用。# encoding: utf-8import clrclr.AddReference("System.Windows.Forms")clr.AddReference("System.Drawing")from System.Windows.Forms import Application, Form, CheckBoxfrom System.Drawing import Size, Pointclass IForm(Form): def __init__(self): self.Text = "CheckBox" self.Size = Size(220, 170) cb = CheckBox() cb.Parent = self cb.Location = Point(30, 30) cb.Text = "Show Title" cb.Checked = True cb.CheckedChanged += self.OnChanged self.CenterToScreen() def OnChanged(self, sender, event): if sender.Checked: self.Text = "CheckBox" else: self.Text = ""Application.Run(IForm()) 效果展示:完整的本地电子版本参阅入门1的其他。来源:CAE中学生