我是python的新手,我想做一个购物车,并且我正在使用w python,我从txt中获取数据,并且完成了window和button事件,但是当我追加数据发送到其他面板,这只能累积到一个点
inventario.txt
asiento_manteca
cacahuate_botanero
cacahuate_chapulin
cecina_enchilada
Chalupas
chapulin_grande
ciruela_curtida
Chocolate_bola_azucarada
Chocolate_bola_pulida
Chocolate_mayordomo
Chocolate_mayordomo_licor
Chocolate_rueda
Chocolate_tablilla
window.py
import wx
import wx.lib.scrolledpanel
productos=[]
with open('inventario.txt') as lineas:
for linea in lineas:
texto=linea.split()
productos.append(texto)
print(texto)
class MiAplicacion(wx.Frame):
def onButton(self, event):
button = event.GetEventObject()
spiner=self.FindWindowByName('s'+button.GetName())
s=spiner.GetValue()
combo=self.FindWindowByName('c'+button.GetName())
print(combo.GetValue())
print(s)
p2=self.FindWindowByName('panel')
p2sz = wx.GridSizer(len(productos),3,2,0)
p2sz.Add(wx.StaticText(p2,label=productos[int(button.GetName())][0]),0,wx.ALL)
p2sz.Add(wx.StaticText(p2,label=str(s)),0,wx.EXPAND)
p2sz.Add(wx.SpinCtrl(p2,label=combo.GetValue()),0,wx.EXPAND)
p2.SetSizer(p2sz)
def __init__ (self,parent,title):
screenSize = wx.DisplaySize()
screenWidth = screenSize[0]
screenHeight = screenSize[1]
wx.Frame.__init__(self,parent=parent,title=title,size=(screenWidth,screenHeight))
p1 = wx.lib.scrolledpanel.ScrolledPanel(self,-1,pos=(0,0),size=(screenWidth/2,screenHeight))
p2 = wx.lib.scrolledpanel.ScrolledPanel(self,-1,pos=(0,screenWidth/2),size=(screenWidth/2,screenHeight/2),name="panel")
p1.SetBackgroundColour('yellow')
p2.SetBackgroundColour('blue')
p1.SetupScrolling()
p2.SetupScrolling()
mainsz = wx.BoxSizer(wx.HORIZONTAL)
p1sz = wx.GridSizer(len(productos),4,2,0)
for i in range (0,len(productos)):
p1sz.Add(wx.StaticText(p1,label=productos[i][0]),0,wx.ALL)
choi=productos[i][1].split('/')
p1sz.Add(wx.ComboBox(p1,value=choi[0],size=(0,0),choices=choi,name='c'+str(i)),0,wx.EXPAND)
p1sz.Add(wx.SpinCtrl(p1,initial=0,max=10000,name='s'+str(i)),0,wx.EXPAND)
b=wx.Button(p1,label = "agregar",name=str(i))
b.Bind(wx.EVT_BUTTON, self.onButton)
p1sz.Add(b)
mainsz.Add(p1,1,wx.ALL,10)
mainsz.Add(p2,1,wx.ALL,10)
p1.SetSizer(p1sz)
self.SetSizer(mainsz)
self.Centre(True)
self.Show()
if __name__=='__main__':
app=wx.App()
frame=MiAplicacion(None,u"Oaxaca")
app.MainLoop()
答案 0 :(得分:0)
您的0 */2 * * * /home/username/test.sh
数据不完整或结构不正确。
我假设您收到以下错误消息:
inventario.txt
Traceback (most recent call last):
File "window.py", line 22, in onButton
p2sz.Add(wx.SpinCtrl(p2,label=combo.GetValue()),0,wx.EXPAND)
TypeError: SpinCtrl(): arguments did not match any overloaded call:
overload 1: too many arguments
overload 2: 'label' is not a valid keyword argument
没有wx.SpinCtrl
,但确实有label
。
将该行更改为:
value
声明
self.p2sz.Add(wx.SpinCtrl(p2,value=str(combo.GetSelection())),0,wx.EXPAND)
在回调self.p2sz = wx.GridSizer(len(productos),3,2,0)
p2.SetSizer(self.p2sz)
中__init__
定义中的 不是
之后,所有对p2sz的引用都应为self.p2sz
实际上,您每次单击按钮时都声明onbutton
。
如果您不熟悉p2sz
,则可能需要查看以下说明:https://medium.com/quick-code/understanding-self-in-python-a3704319e5f0
请注意,您对self
大小调整器的编码风格非常过时,我鼓励您抛弃所有正在使用的资源,寻找更现代的东西,例如https://wiki.wxpython.org/SizerTutorials