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!
as I'm looking into the MVC pattern, I thought I'd create a small application to understand a bit more.
Let's look at the code:
//model package model; public ...
so I can have in first column -00.000146400000 ...
I have an assignment to output contents from a .txt file to html. I'm able to output the information from the .txt to the console but how would I output ...