続 PythonでGUI(コンボボックス)
- hiro2studio
- 2021年2月8日
- 読了時間: 1分
wxPythonでコンボボックスを使う
ボタンとラベルとコンボボックス
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import wx
class TestGUI(wx.Frame):
def __init__(self, parent, id=-1, title='TEST GUI'):
wx.Frame.__init__(self, parent, id, title)
self.SetTitle('TEST GUI')
self.SetSize((300, 200))
panel = wx.Panel(self)
# ボタンの作成
self.Btn = wx.Button(panel, label="push", pos=(120, 10), size=(60, 20))
# ラベルの作成
self.label = wx.StaticText(panel, -1, ' ', pos=(130, 50))
# ボタンを割り当て
self.Bind(wx.EVT_BUTTON, self.push, self.Btn)
# コンボボックス
self.cmb01 = wx.ComboBox(panel, wx.ID_ANY, 'select', choices=[], style=wx.CB_SIMPLE, pos=(60,80), size=(180,24))
self.cmb01.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
self.cmb01.Append('FW', 1)
self.cmb01.Append('MF', 2)
self.cmb01.Append('DF', 3)
self.Show(True)
# コンボボックスイベント
self.Bind(wx.EVT_COMBOBOX, self.cmb01select, self.cmb01)
def push(self, event):
self.label.SetLabel('OK')
def cmb01select(self, event):
print('Position:{}'.format(self.cmb01.GetValue()))
self.label.SetLabel(self.cmb01.GetValue())
#-------------------------------------------------
## main ###
#-------------------------------------------------
if __name__=='__main__':
app=wx.App()
TestGUI(None, wx.ID_ANY, "Btn")
app.MainLoop()
Comments