本入门教程中的所有案例均已测试通过,具体参考入门1中的使用方法。
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 游戏——贪吃蛇
目标:创建控件Label
本案例中展示如何创建Label ,Label非常好用,用于已有的文字说明,标签等,其中的文字一般情况下无法实时变更。
# encoding: utf-8
import sys
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 = """Meet you downstairs in the bar and heard
Your rolled up sleeves and your skull t-shirt
You say why did you do it with him today?
And sniffed me out like I was tanqueray
Cause you're my fella, my guy
Hand me your stella and fly
By the time I'm out the door
You tear me down like roger moore
I cheated myself
Like I knew I would
I told ya, I was trouble
You know that I'm no good
Upstairs in bed, with my ex boy
He's in a place, but I cant get joy
Thinking 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())
效果展示:
目标:创建CheckBox (复选框)
本案例中展示如何创建CheckBox,该控件可用于是否考虑某种条件的情景,非常实用。
# encoding: utf-8
import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Windows.Forms import Application, Form, CheckBox
from System.Drawing import Size, Point
class 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的其他。