Skip to content

Commit 2736e39

Browse files
committed
kivymd lists
1 parent a31c859 commit 2736e39

File tree

7 files changed

+105
-37
lines changed

7 files changed

+105
-37
lines changed
-540 Bytes
Binary file not shown.
1.45 KB
Binary file not shown.

Kivy/helpers.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

Kivy/home.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
from kivymd.app import MDApp
3+
from kivymd.uix.screen import Screen
4+
from kivymd.uix.list import OneLineListItem, MDList
5+
from kivymd.uix.boxlayout import MDBoxLayout
6+
from kivymd.uix.list import IconRightWidget
7+
8+
9+
class DemoApp(MDApp):
10+
11+
def build(self):
12+
13+
screen = Screen()
14+
15+
box_layout = MDBoxLayout(
16+
orientation = "vertical",
17+
spacing = 10,
18+
pos_hint = {"center_x":0.5, "center_y":0.5},
19+
size_hint = (None, None)
20+
)
21+
22+
box_layout.width = 400
23+
24+
list_view = MDList()
25+
26+
icon = IconRightWidget(icon="android")
27+
28+
for lst in range(1, 6):
29+
list_items = OneLineListItem(text=f"List {str(lst)}")
30+
list_view.add_widget(list_items)
31+
32+
list_items.add_widget(icon)
33+
34+
box_layout.add_widget(list_view)
35+
36+
screen.add_widget(box_layout)
37+
38+
39+
return screen
40+
def list_one(self, obj):
41+
print("Hello world")
42+
43+
if __name__ == "__main__":
44+
DemoApp().run()

Kivy/main.py

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,54 @@
1-
1+
import subprocess
22
from kivymd.app import MDApp
33
from kivymd.uix.screen import Screen
44
from kivymd.uix.boxlayout import MDBoxLayout
55
from kivymd.uix.label import MDLabel
6-
from helpers import username_helper, password_helper
76
from kivy.lang import Builder
87
from kivymd.uix.button import MDRaisedButton
98
from kivymd.uix.dialog import MDDialog
109

10+
username_helper = """
11+
MDTextField:
12+
hint_text: "Enter your username"
13+
size_hint_x: None
14+
width: 400
15+
icon_right: "account"
16+
"""
17+
18+
password_helper = """
19+
MDTextField:
20+
hint_text: "Enter your password"
21+
helper_text: "or click on forgot password"
22+
helper_text_mode: "on_focus"
23+
size_hint_x: None
24+
width: 400
25+
icon_right: "key-variant"
26+
password: True
27+
"""
28+
29+
30+
1131
class Demo(MDApp):
1232

1333
def build(self):
1434
screen = Screen()
15-
self.theme_cls.primary_pelatte = "Green"
35+
self.theme_cls.primary_palette = "Green"
1636

1737
box_layout = MDBoxLayout(
18-
orientation = "vertical",
19-
spacing = 20,
20-
pos_hint = {"center_x":0.5, "center_y":0.5},
21-
size_hint = (None, None)
38+
orientation="vertical",
39+
spacing=20,
40+
pos_hint={"center_x": 0.5, "center_y": 0.5},
41+
size_hint=(None, None)
2242
)
2343

24-
2544
# Widgets
2645
label = MDLabel(text="Login", halign="center")
2746
self.username = Builder.load_string(username_helper)
2847
self.password = Builder.load_string(password_helper)
29-
button = MDRaisedButton(text="Login", pos_hint={"center_x":0.5, "center_y":0.5},
30-
on_release=self.show_values)
48+
button = MDRaisedButton(
49+
text="Login", pos_hint={"center_x": 0.5, "center_y": 0.5},
50+
on_release=self.show_values
51+
)
3152

3253
# Add widgets in the box layout
3354
box_layout.add_widget(label)
@@ -42,16 +63,30 @@ def build(self):
4263
screen.add_widget(box_layout)
4364

4465
return screen
45-
66+
4667
# Function for showing the dialog
4768
def show_values(self, obj):
48-
close_btn = MDRaisedButton(text="Close")
49-
more_btn = MDRaisedButton(text="More")
50-
dialog = MDDialog(title="Show details",
51-
text=f"Username: {self.username.text} \n\nPassword: {self.password.text}",
52-
size_hint=(0.7, 1),
53-
buttons=[close_btn, more_btn])
54-
dialog.open()
55-
69+
if self.username.text == "":
70+
check_string = "Please enter username"
71+
else:
72+
check_string = "Username does not exist"
73+
74+
close_btn = MDRaisedButton(text="Close", on_release=self.close_dialog)
75+
more_btn = MDRaisedButton(text="More", on_release=self.open_home)
76+
77+
self.dialog = MDDialog(
78+
title="Show details",
79+
text=f"Username: {check_string} \n\nPassword: {self.password.text}",
80+
buttons=[close_btn, more_btn]
81+
)
82+
self.dialog.open()
83+
84+
def open_home(self, obj):
85+
# Use subprocess to run home.py
86+
subprocess.run(["python", "home.py"])
87+
88+
def close_dialog(self, obj):
89+
self.dialog.dismiss()
90+
5691
if __name__ == "__main__":
5792
Demo().run()

Kivy/tempCodeRunnerFile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from kivymd.uix.datepicker import MDDatePicker # Correct approach

Utility programs/algotrithms

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
num = 10
3+
4+
sum1 = (num*(num+1))/2
5+
6+
print(sum1)

0 commit comments

Comments
 (0)