This is how I would do it ... ''' kivy_button_label101.py create a touch sensitive button with Python module kivy add a label to show action info: http://kivy.org/docs/api-kivy.uix.button.html http://kivy.org/docs/api-kivy.uix.label.html http://kivy.org/docs/api-kivy.uix.boxlayout.html ''' from kivy.app import App from kivy.uix.button import Button from kivy.uix.label import Label from kivy.uix.boxlayout import BoxLayout class TestApp(App): def build(self): … Read More
I think i should use
on_press keyword, but i don't know how to use it exactly. I need a simple example. For example i want when i press the button, a "Hello World" apperas on the label widget. (All in kivy language).
Which tutorial are you using?
Well, i'm trying to learn from every where. If h find any video i watch it, i search the net and try to learn from example codes. I didn't find any special and great tutorial for that.
I checked that link but as i said, it's not clear for me how to use it exactly.
I know i should create a .py file and a .kv file, but i think that link is about only what we can use in .py file only.
I mean some tutorials use kivy in one .py file only and don't teach the standard way of kivy programming wich should use a .kv file beside the .py file and changing the .py file according to that .kv file.
Well, i don't know it was clear or not.
I nead a simple and complete example, a .py file and a .kv file to gather to see how they interact.
This is how I would do it ...
''' kivy_button_label101.py create a touch sensitive button with Python module kivy add a label to show action info: http://kivy.org/docs/api-kivy.uix.button.html http://kivy.org/docs/api-kivy.uix.label.html http://kivy.org/docs/api-kivy.uix.boxlayout.html ''' from kivy.app import App from kivy.uix.button import Button from kivy.uix.label import Label from kivy.uix.boxlayout import BoxLayout class TestApp(App): def build(self): layout = BoxLayout(orientation='vertical') # use a (r, g, b, a) tuple blue = (0, 0, 1.5, 2.5) red = (2.5, 0, 0, 1.5) btn = Button(text='Touch me!', background_color=blue, font_size=120) btn.bind(on_press=self.callback) self.label = Label(text="------------", font_size='50sp') layout.add_widget(btn) layout.add_widget(self.label) return layout def callback(self, event): print("button touched") # test self.label.text = "button touched" TestApp().run()
Edited by vegaseat
Thank you @vegaseat.
I have some question again:
Look at line 24.
self.label = what does the "self" word do here?
And line 29.
def callback(self, event): what the "self" keyword is for? I don't know much about the SELF keyword.
And also what does the "event" keyword do here?
Thanks for this simple example, this is one way, we just have one .py file. Can you give me an example of using one .py file and one .kv file beside togather, that they are interacting togather, do you know what i mean?
If i want to create this program in that way with both .kv and .py file togather, i can't do it. The standard form of coding in kivy language is using a .py file and a .kv file togather, right?!
I would be happy if you could give me an example of that way too.
Thanks for this one, it helps.
You need to learn the basics of a Python class!
bind() creates an event that is send to callback()
I don't use .kv files for simple programs, just another special syntax to manage and errors are hard to trace!
Edited by vegaseat
As a GUI toolkit Kivy is pretty clumsy. I would use it only if you want to use your touch sensitive screen or for Android applications.
But Tkinter is really ugly so i prefer to use Kivy, it's more beautiful than Tkinter! And also very easy to code!
Provides a secure frontend object with restricted access to attributes of the backend object.
I am new to python.
is there a program i could use to make a Clock with day and date in big fonts to help my gran with ...
I have to create a program to only be used as a tool (no main function). Below is the background information related to task:
Your goal for this ...