'Update A screen in kivy
Hi i am writing a program for my uncles business where he can scan barcodes to keep inventory, im jsut trying to get the part where he can see what all is in his inventory and i have ran into a issue where i need to update a screen when i click on a button so i can see the updated text file how would i go about this?
python file:
class HomeScreen(Screen):
pass
class ViewBarcode(BoxLayout):
pass
class Scroll(ScrollView):
pass
class Stack(StackLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
f = open(f'{cwd}/items/items.txt', 'r')
lines = f.readlines()
for i in lines:
b1 = Button(
text=str(i),
size_hint=(1, None),
size=(200, dp(50)),
)
b1.bind(on_press=self.button1)
self.add_widget(b1)
def button1(self, instance):
id = (instance.text).replace('\n', '')
f = open(f'{cwd}/items/{id}.txt', 'r')
lines = f.readlines()
print(instance.text)
print(f'''Item Name: {lines[0]}\nPrice: {lines[1]}''')
f = open(f'{cwd}/depends/temps.txt', 'w')
f.write(str(id))
f.close()
App.get_running_app().root.current = 'ViewItem'
class ViewItemScreen(Screen):
f = open(f'{cwd}/depends/temps.txt', 'r')
lines = f.readlines()
barcode = lines[0]
f = open(f'{cwd}/items/{barcode}.txt', 'r')
lines = f.readlines()
name = lines[0]
price = lines[1]
name = lines[0]
class barcode(App):
def build(self):
sm = ScreenManager()
sm.add_widget(HomeScreen(name='HomeScreen'))
sm.add_widget(ViewItemScreen(name='ViewItem'))
return sm
barcode().run()
.kv file
HomeScreen:
<HomeScreen>:
BoxLayout:
cols:2
BoxLayout:
cols:2
size_hint: .5,1
orientation: 'vertical'
TextInput:
size_hint: 1,1
text: 'Enter Barcode'
multiline: False
on_text_validate: pass
Button:
#size_hint: .5,1
text: 'hi'
Scroll:
size_hint: .5,1
Stack:
size_hint: 1,None
height: self.minimum_height
<ViewItemScreen>:
ViewBarcode:
BoxLayout:
size_hint:.25,1
BoxLayout:
orientation: 'vertical'
Button:
text: 'home'
size_hint: .25,.25
on_press: root.manager.current = 'HomeScreen'
#Label:
# size_hint: .25,.75
BoxLayout
orientation: 'vertical'
TextInput:
text: root.barcode
TextInput:
text: root.name
TextInput:
text: root.price
Label
size_hint: .25,1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
