March 01, 2021

create text input and submit button using kivy python

kivy project



 import kivy

from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button

class MyGradeLayout(GridLayout):
def __init__(self, **kwargs):
super(MyGradeLayout,self).__init__(**kwargs)
self.cols=2
#name:
self.add_widget(Label(text='name : ',font_size=30))
self.name=TextInput(multiline=False)
self.add_widget(self.name)
#movies:
self.add_widget(Label(text='movies : ',font_size=30))
self.movies = TextInput(multiline=False)
self.add_widget(self.movies)
#ratig:
self.add_widget(Label(text='rating : ',font_size=30))
self.rating = TextInput(multiline=False)
self.add_widget(self.rating)
#button
self.submit=Button(text="submit",font_size=32)
self.submit.bind(on_press = self.press)
self.add_widget(self.submit)

def press(self,instance):
name = self.name.text
movies = self.movies.text
rating = self.rating.text
#print(f"hello {name}, you love {movies}, because the rating of this moves is {rating}")
self.add_widget(Label(text=f"Hello {name},\n you love '{movies}' movies,\n because the rating of this moves is {rating}"))
#after press the button clear input boxes
self.name.text=""
self.rating.text=""
self.movies.text=""



class MyApp(App):
def build(self):
return MyGradeLayout()


if __name__=='__main__':
MyApp().run()

No comments:

Post a Comment

find the cube of the range given digits. || codeAj

Find the cube of the range given Digits. Source Code r= int ( input ( "enter the range of digit : " )) def number_conter (n): ...