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 1 Year Ago 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 1 Year Ago 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!
Hello All ...
Iam Getting An Error With try to excecute the stored procedure .
I have Have Sql database , the stored procedure like so :
USE [MPRS] GO /****** Object: StoredProcedure [dbo].[Search_Licenses_By_Number] Script Date: 26-Nov-16 8:06:52 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE ...
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...
Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...