Reputation: 1
I'm trying to make an app that can automate an Instagram page, and I have the script for the program ready, but just need to implement it into a GUI. For this, I'm using Kivy. However, I only need to send one request to the API for this. When I click on a button, it triggers the command attached to on_release of the button twice. How can I fix this?
Simplified Python Script:
from kivymd.app import MDApp
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.lang import Builder
class StartScreen(Screen):
pass
class WindowManager(ScreenManager):
pass
class BruhApp(MDApp):
def build(self):
self.root = Builder.load_file("bruh.kv")
if __name__ == '__main__':
BruhApp().run()
.kv File:
WindowManager:
StartScreen:
<StartScreen>:
name: "start"
FloatLayout:
MDLabel:
text: "Welcome to the Instagram Page Automator!"
font: "RobotoThin"
font_style: "H5"
halign: "center"
size_hint:0.9,0.7
color: 0,0,0,0.5
pos_hint:{"center_x":0.5,"y":0.5}
MDFillRoundFlatButton:
md_bg_color: 0, 1, 0.6, 1
text:"Continue"
font: "RobotoThin"
size_hint:0.4,0.07
pos_hint:{"center_x":0.5,"y":0.1}
on_release:
print("yes")
This script prints "Yes" twice for me everytime I press the button.
Upvotes: 0
Views: 471
Reputation: 38837
The kivy system automatically loads a kv
file for an App
if the file is correctly named (See the documentation). Since your kv
file is correctly named, it will be loaded automatically. But since you also load it explicitly using the line:
self.root = Builder.load_file("bruh.kv")
the kv
file actually gets loaded twice, which causes some things to be instantiated twice. Try replacing the build()
method with a simple pass
.
Upvotes: 2