mfc combobox dropdown中编辑框不可输入的属性设置_Office办公“革命之路”——实现Python的GUI的可视化输入...

实现GUI的搭建,可视化输入

(1)有许多图形用户界面(GUI)工具包可以与Python编程语言一起使用。其中三巨头是Tkinter、wxPython和PyQt。这些工具包中的每一个都将与Windows、macOS和Linux一起工作,而PyQt具有在移动设备上工作的附加功能。

(2)Python GUI,首先要说的是:MACOS系统不支持PyQt5-tools,虽然可以下载PyQt5。

ERROR: Could not find a version that satisfies the requirement
pyqt5-plugins~=5.15.1.1.0.dev0 (from PyQt5-tools) (from versions:
none) ERROR: No matching distribution found for
pyqt5-plugins~=5.15.1.1.0.dev0 (from PyQt5-tools)

(3)wxPython GUI工具包是一个围绕名为wxWidgets的c++库的Python包装器。wxPython的最初版本是在1998年发布的,所以wxPython已经存在很长时间了。wxPython与其他工具包(如PyQt或Tkinter)的主要区别在于,wxPython尽可能在本机平台上使用实际的小部件。这使得wxPython应用程序看起来与它所运行的操作系统是原生一体的。
(4)pip 安装wxPython

pip install wxpython

7721c13e82991a60c2d5c8a286fab36a.png87b622a0d8207100099c9181d015a551.png
(5)导入wxpython

import wx

(6)一个简单的GUI应用程序显示Hello World消息,使用以下构建步骤 :

import wx# 1. 导入 wx 模块
app = wx.App()# 2. 定义应用程序类的一个对象
window = wx.Frame(None, title="wxPython", size=(300, 300))#创建一个顶层窗口的 wx.Frame 类的对象。给出构造标题和尺寸参数。
panel = wx.Panel(window)# 4. 虽然其他控件可以在Frame对象加入,但它们的布局无法管理。因此,把一个Panel对象到框架。
label = wx.StaticText(panel, label="Hello World", pos=(100, 100))#5.添加一个静态文本对象,以显示 ‘Hello World’在窗口内的任意位置。
window.Show(True)#6.通过show()方法激活框架窗口。
app.MainLoop()# 7. 输入应用程序对象的主事件循环。

2ccaceb3b12a79c9eb78db324232c4e0.png
(7)wx.Frame类不带参数的默认构造函数。

Wx.Frame (parent, id, title, pos, size, style, name)

(8)wxPython Panel类
小构件,如按钮,文本框等被放置在面板窗口。
(9)wxPython TextCtrl类
在GUI接口中,输入是最常见的是在一个文本框收集,用户可以使用键盘键入。

wx.TextCtrl(parent, id, value, pos, size, style) 

样式(style)参数接受一个或多个常量:

wx.TE_MULTILINE#文本控件允许多行。如果未指定该样式(style),换行字符不应该在控件值中使用。
wx.TE_PASSWORD#文本将回显为星号
wx.TE_READONLY#文本将不可编辑
wxTE_LEFT#	在控件中的文本将左对齐(默认)
wxTE_CENTRE#在控件中的文本将居中对齐
wxTE_RIGHT#在控件中的文本将居右对齐

(10)wxPython ComboBox & Choice类

wx.ComboBox对象提供从项目选择列表。

 text1=wx.StaticText(parent=panel,id=-1,pos=(10,5),label="选择签约主体:")
list1=["某某1","某某2"]
self.combobox1=wx.ComboBox(parent=panel,id=-1,pos=(100,5),value="某某1",choices=list1 )#wx.ComboBox 默认它的文本框是可以修改的

(11)wxPython Button控件
在任何GUI界面按钮组件的应用最为广泛。它捕获用户生成的点击事件。其最明显的用途是触发绑定到一个处理函数。

Wx.Button(parent, id, label, pos, size, style)
self.button = wx.Button(panel, -1, "提交", pos=(600, 40), size=(80, 80))  # 在面板上添加控件
self.Bind(wx.EVT_BUTTON, self.OnClick, self.button) # 将回调函数与按键事件绑定

(一)需求梳理一下,在UI界面中实现:下拉菜单点选或填写基本信息,点击“提交”按钮后,能够把点选或填写的保存下来,每一次点击“提交”按钮后,更新最新的填写的信息并且保存,最后这些信息能够作为其他python程序的输入信息,生成一系列信息完整的word或者excel文档为我所用。
1、模块举例一:

 text1=wx.StaticText(parent=panel,id=-1,pos=(10,5),label="选择签约主体:")
list1=["南京电信","中电鸿信"]
self.combobox1=wx.ComboBox(parent=panel,id=-1,pos=(100,5),value="南京电信",choices=list1 )#wx.ComboBox 默认它的文本框是可以修改的

72db3eab8da89c74b801c173b3945bd5.png
2、模块举例二:
st16 = wx.StaticText(panel, -1, “付款方式:”, pos=(180, 150))
self.txt16 = wx.TextCtrl(panel,-1, pos=(260, 150), size=(300, 20))c14c1b9aaf7bb9cba2964b7d722a99e0.png
3、模块举例三:

 #提交模块
self.button = wx.Button(panel, -1, "提交", pos=(600, 40), size=(80, 80)) # 在面板上添加控件
self.Bind(wx.EVT_BUTTON, self.OnClick, self.button) # 将回调函数与按键事件绑定

da08a0bf6e69ce84bd8030b8b81e41c1.png
4、数据信息保存(涉及20左右的信息保存),保存至“abc.npz”文件。

             a=self.combobox1.GetValue()
b = self.combobox2.GetValue()
c1=self.txt1.GetValue()
c2= self.txt2.GetValue()
c3= self.txt3.GetValue()
c4 = self.txt4.GetValue()
c5= self.txt5.GetValue()
c6= self.txt6.GetValue()
c7= self.txt7.GetValue()
c8= self.txt8.GetValue()
c9= self.txt9.GetValue()
c10= self.txt10.GetValue()
c11= self.txt11.GetValue()
c12= self.txt12.GetValue()
c13= self.txt13.GetValue()
c14= self.txt14.GetValue()
c15 = self.txt15.GetValue()
c16 = self.txt16.GetValue()
c17 = self.txt17.GetValue()
c18 = self.txt18.GetValue()
c19 = self.txt19.GetValue()
c20= self.combobox20.GetValue()

np.savez('abc.npz', k_a=a, k_b=b,k_c1=c1,k_c2=c2,k_c3=c3,k_c4=c4,k_c5=c5,k_c6=c6,k_c7=c7,k_c8=c8,k_c9=c9,k_c10=c10,k_c11=c11,k_c12=c12,k_c13=c13,k_c14=c14,k_c15=c15,k_c16=c16,k_c17=c17,k_c18=c18,k_c19=c19,k_c20=c20)

5、完整代码:(其中涉及商业机密的部分内容已经用“*****************************”替代。)

import wx
import numpy as np
import wx.grid
APP_TITLE = 'Log in'
class MyFrame(wx.Frame):
ClickNum = 0
def __init__(self): #__init__(self) 是类的初始化方法,也称构造方法,是一种特殊的魔法方法。__init__(self)在实例化后,会自动调用,而不用手动调用,所以一般把属性设置在_init__()里。
super().__init__(parent=None,title="采购基本信息填写",size=(1000,700)) # 初始化窗口信息
panel=wx.Panel(self) #框架的父窗口。对于顶级窗口,这个值是None 。#创建面板
#模块1 选择签约主体
#self.Center()


text1=wx.StaticText(parent=panel,id=-1,pos=(10,5),label="选择签约主体:")
list1=["******","*******"]
self.combobox1=wx.ComboBox(parent=panel,id=-1,pos=(100,5),value="****",choices=list1 )#wx.ComboBox 默认它的文本框是可以修改的

#提交模块
self.button = wx.Button(panel, -1, "提交", pos=(600, 40), size=(80, 80)) # 在面板上添加控件
self.Bind(wx.EVT_BUTTON, self.OnClick, self.button) # 将回调函数与按键事件绑定

#模块2 选择支局
list2=["六合竹镇支局","六合龙池支局","六合雄州支局","六合马鞍支局","六合冶山支局","六合横梁支局","六合龙袍支局","六合东沟支局","六合行客支局","六合新城支局","六合金牛湖支局","六合程桥支局","六合六城支局"]
text2 = wx.StaticText(parent=panel, id=-1, pos=(10,100),label="选择支局:")
self.combobox2=wx.ComboBox(parent=panel,id=-1,pos=(80,100),choices=list2) #wx.Choice 是只读不可以修改的
#choice.SetSelection(0)
#self.Bind(wx.EVT_CHOICE,self.on_choice,self.choice)
hbox2 = wx.BoxSizer()

list20=["(含税13%、含税6%)","(含税6%)","(含税13%)","(含税9%)"]
text20 = wx.StaticText(parent=panel, id=-1, pos=(260,100),label="含税税率:")
self.combobox20=wx.ComboBox(parent=panel,id=-1,pos=(360,100),choices=list20)

st1 = wx.StaticText(panel, -1, "项目名称:", pos=(10, 50))
self.txt1 = wx.TextCtrl(panel,-1, pos=(80, 40), size=(200, 50),style=wx.TE_MULTILINE | wx.HSCROLL)

sizer = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)

st2 = wx.StaticText(panel, -1, "工期(天):", pos=(10, 150))
self.txt2 = wx.TextCtrl(panel,-1, pos=(90, 150), size=(50, 20))

st16 = wx.StaticText(panel, -1, "付款方式:", pos=(180, 150))
self.txt16 = wx.TextCtrl(panel,-1, pos=(260, 150), size=(300, 20))

st3 = wx.StaticText(panel, -1, "维保期(年):", pos=(10, 200))
self.txt3 = wx.TextCtrl(panel,-1, pos=(100, 200), size=(50, 20))

st4 = wx.StaticText(panel, -1, " 2.3资质条件:", pos=(10, 250))
list4=["********************************************************************************** "]
self.txt4 = wx.ComboBox(parent=panel,id=-1,pos=(100,250),value="**********************************************************************************",choices=list4)
#self.Bind(wx.EVT_CHOICE, self.on_choice, choice)

st5 = wx.StaticText(panel, -1, " 2.4资质条件:", pos=(10, 300))
list5 = ["**********************************************************************************",
"********************************************************************************** "]
self. txt5 = wx.ComboBox(parent=panel, id=-1, pos=(100, 300), value="*******************************************************************",
choices=list5)
st6 = wx.StaticText(panel, -1, " 报名方式:", pos=(10, 350))
list6 = ["**********************************************************************************"]
self.txt6 = wx.ComboBox(parent=panel, id=-1, pos=(100, 350), value="**********************************************************************************",
choices=list6)
st7 = wx.StaticText(panel, -1, "设备部分限价(元):", pos=(10, 400))
self.txt7 = wx.TextCtrl(panel, -1, pos=(140, 400), size=(100, 20))

st8 = wx.StaticText(panel, -1, "服务部分限价(元):", pos=(10, 450))
self.txt8 = wx.TextCtrl(panel, -1, pos=(140, 450), size=(100, 20))

st17 = wx.StaticText(panel, -1, "业绩(万元):", pos=(300, 450))
self.txt17 = wx.TextCtrl(panel, -1, pos=(440, 450), size=(100, 20))

st9 = wx.StaticText(panel, -1, "设备数量:", pos=(10, 500))
self.txt9 = wx.TextCtrl(panel, -1, pos=(140, 500), size=(100, 20))

st15=wx.StaticText(panel, -1, "服务数量:", pos=(300, 500))
self.txt15 = wx.TextCtrl(panel, -1, pos=(430, 500), size=(100, 20))


st10 = wx.StaticText(panel, -1, "设备及相关集成服务:", pos=(10, 550))
self.txt10 = wx.TextCtrl(panel, -1, pos=(140, 550), size=(600, 20))

st11 = wx.StaticText(panel, -1, "询价文件发布时间:", pos=(10, 600))
self.txt11 = wx.TextCtrl(panel, -1, pos=(140, 600), value="2020年11月日",size=(600, 20))

st12 = wx.StaticText(panel, -1, "询价文件获取时间:", pos=(10, 650))
self.txt12 = wx.TextCtrl(panel, -1, pos=(140, 650), value="2020年11月日8:30:00(北京时间,下同)至 2020年11月日17:30:00。", size=(600, 20))

st13 = wx.StaticText(panel, -1, "开标时间:", pos=(10, 700))
self.txt13 = wx.TextCtrl(panel, -1, pos=(140, 700), value="2020年11月日",size=(500, 20))

st18 = wx.StaticText(panel, -1, "开标具体时间:", pos=(700, 700))
self.txt18 = wx.TextCtrl(panel, -1, pos=(800, 700), value="2020年11月日下午15时30分",size=(400, 20))


st14 = wx.StaticText(panel, -1, "应答截止时间:", pos=(10, 750))
self.txt14 = wx.TextCtrl(panel, -1, pos=(140, 750), value="2020年11月日",size=(500, 20))

st19 = wx.StaticText(panel, -1, "开标前一天:", pos=(700, 750))
self.txt19 = wx.TextCtrl(panel, -1, pos=(800, 750), value="2020年11月日",size=(400, 20))
self.CreateStatusBar()
self.SetStatusText("准备就绪")
def OnClick(self, event): #回调函数事件
self.button.SetLabel("提交成功") #设置
self.ClickNum+=1
if self.ClickNum % 2 == 1: #根据按下次数判断
self.button.SetLabel("已经提交")#修改按键的标签
a=self.combobox1.GetValue()
b = self.combobox2.GetValue()
c1=self.txt1.GetValue()
c2= self.txt2.GetValue()
c3= self.txt3.GetValue()
c4 = self.txt4.GetValue()
c5= self.txt5.GetValue()
c6= self.txt6.GetValue()
c7= self.txt7.GetValue()
c8= self.txt8.GetValue()
c9= self.txt9.GetValue()
c10= self.txt10.GetValue()
c11= self.txt11.GetValue()
c12= self.txt12.GetValue()
c13= self.txt13.GetValue()
c14= self.txt14.GetValue()
c15 = self.txt15.GetValue()
c16 = self.txt16.GetValue()
c17 = self.txt17.GetValue()
c18 = self.txt18.GetValue()
c19 = self.txt19.GetValue()
c20= self.combobox20.GetValue()

np.savez('abc1.npz', k_a=a, k_b=b,k_c1=c1,k_c2=c2,k_c3=c3,k_c4=c4,k_c5=c5,k_c6=c6,k_c7=c7,k_c8=c8,k_c9=c9,k_c10=c10,k_c11=c11,k_c12=c12,k_c13=c13,k_c14=c14,k_c15=c15,k_c16=c16,k_c17=c17,k_c18=c18,k_c19=c19,k_c20=c20)

print("签约主体:" + self.combobox1.GetValue())
print("选择支局: " + self.combobox2.GetValue())
print("项目名称:" + self.txt1.GetValue())
print("工期(天):" + self.txt2.GetValue())
print("维保期(年):" + self.txt3.GetValue())
print("2.3资质条件:" + self.txt4.GetValue())
print("2.4资质条件:" + self.txt5.GetValue())
print("报名方式:" + self.txt6.GetValue())
print("设备部分限价(元):" + self.txt7.GetValue())
print("服务部分限价(元):" + self.txt8.GetValue())
print("设备数量:" + self.txt9.GetValue())
print("设备及相关集成服务:" + self.txt10.GetValue())
print("询价文件发布时间:" + self.txt11.GetValue())
print("询价文件获取时间:" + self.txt12.GetValue())
print("开标时间:" + self.txt13.GetValue())
print("应答截止时间:" + self.txt14.GetValue())
print(self.button.GetLabel())#打印信息(返回按键的标签信息)

else:
#self.button.SetLabel("登录")
self.ClickNum = 0
print(self.button.GetLabel())



class mainApp(wx.App):
"""
在OnInit() 里边申请Frame类,这样能保证一定是在app后调用,
这个函数是app执行完自己的__init__函数后就会执行
"""

def OnInit(self):
self.Frame = MyFrame(None)
self.Frame.Show()
return True

"""
在def OnExit(self):这个是窗口关闭后调用的函数,
把要释放的非wx资源或者要保存的放到这个函数里,
优雅的退出不留遗憾
"""

def OnExit(self):
self.Frame.ExitFrame()
print("关闭窗口后调用,可以在这里保存一些相关的配置")
pass


class App(wx.App):
def OnInit(self):
frame=MyFrame()
frame.Show()
return True


if __name__=="__main__" :#在python中使用__开头 并以__结尾的方法,称之为魔法方法;
app=App()
app.MainLoop()

最后的UI输入界面:

6c582999286fbcdbe96989cecd15f6fc.png

点击“提交”按钮后,6d48d7ef0038b4228ffdd87299927eb4.png25d02e75272747062ccf05e0114ef24f.png
在其他程序里面,通过np.load('abc.npz')就可以实现调用数据,一键生成word以及excel文档!

import numpy as np
from decimal import Decimal

data_a = np.load('abc.npz')

Project_name=data_a['k_c1']#项目名称
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值