if os.name == "nt":
startupinfo = subprocess.STARTUPINFO()
#startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
GUI入門したら、このページをおすすめします。英語ですが、わかりやすく、step-by-stepで教えてもらいます。
ただし、copy-pasteをやめた方がいい。コードを書いて、実行した方が覚えやすいだろう。
wxPythonは人気があるので、使っています(ミーハーですね(笑))。
基本的な知識は、このページを説明します。
ちょっとwxPythonのwidgetsのことをメモします。
wx.Button
ボタンを作るウィジェット。一つの文字列を含む。
sizer = wx.GridBagSizer()
button = wx.Button(self, -1, label='Click me!') #ボタンを作る
sizer.Add(button, (0, 1)) #位置を決める
button.Bind(wx.EVT_BUTTON, self.OnClickButton) #ボタンをクリックしたら何かやる
wx.ToggleButton
2つの状態があるボタン。「クリックしている」と「クリックしていない」。
rtb.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleRed)
def ToggleRed(self, event):
obj = event.GetEventObject()
isPressed = obj.GetValue()
if isPressed:
#
else:
#
wx.StaticLine
横や縦の一般の線を作る。
wx.StaticLine(self, pos=(25, 260), size=(300,1))
wx.StaticText
読み専用の文字列を表示する。
wx.StaticText(self, label='5 445 000', pos=(250, 80))
wx.StaticBox
普通のボックスを書く。
wx.StaticBox(self, -1, 'Personal Info', (5, 5), size=(240, 170))
wx.ComboBox
テキストボックスの右端のボタンを押すと選択可能な項目の一覧が表示され、その中からひとつを選ぶことができるコンボボックス。
distros = ['Ubuntu', 'Arch', 'Fedora', 'Debian', 'Mint']
cb = wx.ComboBox(pnl, pos=(50, 30), choices=distros, style=wx.CB_READONLY)
def OnSelect(self, event):
i = event.GetString()
wx.CheckBox
チェックボックスを作る
cb = wx.CheckBox(pnl, label='Show title', pos=(20, 20))
cb.Bind(wx.EVT_CHECKBOX, self.ShowOrHideTitle)
def ShowOrHideTitle(self, e):
sender = e.GetEventObject()
isChecked = sender.GetValue()
if isChecked:
#
else:
#
wx.RadioButton
複数の選択肢から1つだけを選択する場合に用いられるラジオボタン。
self.rb1 = wx.RadioButton(pnl, label='Value A', pos=(10, 10),
style=wx.RB_GROUP)
self.rb2 = wx.RadioButton(pnl, label='Value B', pos=(10, 30))
self.rb3 = wx.RadioButton(pnl, label='Value C', pos=(10, 50))
style=wx.RB_GROUPから新たなグループを作る。例えば、
self.rb1 = wx.RadioButton(pnl, label='Value A', pos=(10, 10),
style=wx.RB_GROUP)
self.rb2 = wx.RadioButton(pnl, label='Value B', pos=(10, 30),
style=wx.RB_GROUP
)
self.rb3 = wx.RadioButton(pnl, label='Value C', pos=(10, 50))
では、{1}と{2,3}との2つのグループを作った。値はself.rb1.GetValue()で取れる。