【发布时间】:2020-10-02 12:16:58
【问题描述】:
很抱歉,如果某些部分是我的语言,希望没关系
当我按下“添加”按钮添加另外 3 个文本输入时,例如“添加”按钮上的那些,我想保存放在这些文本输入框上的输入,但我想我可以自己弄清楚。
我搜索但找不到有用的东西。这也是我第一次在这个级别上创建一些东西,如果它在某些方面效率低下,非常抱歉。
这是py 文件:
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.properties import ObjectProperty
class MyGrid(GridLayout) :
id_1 = ObjectProperty(None)
id_2 = ObjectProperty(None)
id_3 = ObjectProperty(None)
id_4 = ObjectProperty(None)
id_10 =ObjectProperty(None)
def perfundo (self) :
file = open('F:\\F\\F\\' + self.id_1.text + '-' + str(date.today()) + '.txt', 'x')
file.write('Emri dhe mbiemri :' + self.id_1.text + '\n' + 'Lloji i vetures :' + self.id_2.text + '\n' + 'Nr. i telefonit :' + self.id_3.text + '\n' + 'Problemi :' + self.id_4.text)
file.close()
def add(self):
self.id_10.text
class HAZApp(App) :
def build (self) :
return MyGrid()
app = HAZApp()
app.run()
这是kv文件
<MyGrid>
id: HAZ
id_1: emridhembiemri
id_2:llojiivetures
id_3:numriitelefonit
id_4:problemi
id_10:add
rows: 10
padding: 10
spacing: 10
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: 'photo.jpg'
BoxLayout:
canvas.before:
Color:
rgba: 0.4,0.5,0.8,1
Rectangle:
size: self.size
pos: self.pos
Label:
font_size: '40sp'
outline_color: 0, 0, 0
outline_width: 2
text: 'Auto Servis "Haziri"'
BoxLayout:
spacing:10
Label:
text:"Name"
font_size: 20
color:0.4,0.5,0.8,1
Label:
text:"Type of car"
font_size: 20
color:0.4,0.5,0.8,1
Label:
text:"Phone number"
font_size: 20
color:0.4,0.5,0.8,1
Label:
text:"Problem"
font_size: 20
color:0.4,0.5,0.8,1
BoxLayout:
spacing:20
TextInput:
font_size: 20
id:emridhembiemri
TextInput:
font_size: 20
id:llojiivetures
TextInput:
font_size: 20
id:numriitelefonit
TextInput:
font_size: 20
id:problemi
BoxLayout:
spacing: 20
column:2
Label:
text:'Parts'
font_size: 20
color:0.4,0.5,0.8,1
BoxLayout:
Label:
text:'price for parts'
font_size: 20
color:0.4,0.5,0.8,1
Label:
text:'price for work'
font_size: 20
color:0.4,0.5,0.8,1
BoxLayout:
spacing: 20
column:2
TextInput:
BoxLayout:
TextInput:
TextInput:
BoxLayout:
Button:
id:add
text:'Add'
on_press:root.add()
BoxLayout:
column:4
Label:
text:''
Label:
text:''
Label:
text:''
Label:
text:'Total'
BoxLayout:
column:4
Label:
text:''
Label:
text:''
Label:
text:''
Button:
text:'total'
BoxLayout:
Label:
text:''
Button:
text:'Finish'
font_size: 20
on_press:root.perfundo()
on_press: app.stop()
Label:
text:''
【问题讨论】:
标签: python button kivy kivy-language textinput