How to exit a Kivy application using a button - python

I'm just learning Python and the Kivy framework. I can't seem to find any specific complete examples of being able to gracefully exit a Kivy app using code linked to a button.
I have found Kivy code snippets like this
Button:
id:btnExit
text:"Exit"
on_press: app.Exit()
But not any matching code that implements the app.Exit() call. Everything I've tried stops code execution but doesn't clean up the program window.
I've read that Android and iOS style guides state that a program is not to programmatically exit and let the OS handle it but I am developing fullscreen borderless Desktop app and need a way to exit the program with a button press.

Use App.stop(*largs):
Button:
id: btnExit
text: "Exit"
on_press: app.stop()

Try using App.get_running_app().stop().
For more details, read the Kivy documentation article for the function.

Try using self.root_window.close().
There is bug in new android toolchain.

I used
on_press : app.stop()
in Button's property in Kivy Layout File and it worked well for me.

Related

Unable to find button's name with Pywinauto anymore

I have a very strange problem.
I am writing a script with Pywinauto for automatic testing on an application. I have to open a window by clicking on a button named "FATO".
For the previous version of the application, the script worked well. When I use print_control_identifiers(), I find the correct name and the button type : uia_controls.ButtonWrapper - 'FATO ', Button
In the new version of the application, the script doesn't work anymore. It doesn't find the button: uiawrapper.UIAWrapper - '', Pane
According to the developer, there was no change on this button. What is strange is that all the buttons of the toolbar have the same behaviour.
What is the 'Pane' type and why Pywinauto does not recognize the button's name and its type anymore ?

Binding button in Kivy makes funciton run when the program is run

Im using
Button:
on_press: app.test()
But whenever I run the program instead of showing a button the function I've binded it to just runs automatically. Any ideas on what I could be doing wrong
you should probably do
root.test()
not
app.test()

Kivy on Windows10. How to click a button, when kivy application does not in focus?

I have a simple kivy app with 3 buttons. When my kivy app is not in focus, I have to click on it once, in order to press any button. How can I click any button with only one click without activating a kivy window?
#:kivy 1.10.0
cannot press any button, when a window is not in focus
I encountered this issue recently as well. Couldn't find a solution but I did implement a workaround that worked. What I did was bound kivy.core.window.Window to on_cursor_enter to trigger a callback that brings the kivy app to foreground, gaining focus, whenever the mouse enters back into the kivy app window:
Window.bind(on_cursor_enter=mouseEnter)
def mouseEnter(instance):
Window.raise_window()
I was inspired by Jack's answer. I have found that Window.raise_window causes the taskbar icon to start flashing (at least on Windows 10), so I would recommend using Window.show instead. This seems to work just the same, but does not make the taskbar icon flash.
Full code:
Window.bind(on_cursor_enter=lambda *__: Window.show())
Just add the following at the top of your code:
import os
os.environ["SDL_MOUSE_FOCUS_CLICKTHROUGH"] = '1'
See discussion at:
https://groups.google.com/g/kivy-users/c/b1wXKpjzjkg/m/5HF6WxSyAwAJ

Coding with Python + Kivy - Desktop Application Interface

I've beeing coding applications for years using C# and Delphi. And one of the greatest things of those languages, in my opinion, was how easy it was to code the interface - you could grab the buttons, make the rectangles and etc, all using the mouse, dragging the squares.
Now I'm interested in Kivy, using Python. Can I construct the desktop interface just like Delphi, using the mouse and making the layout easily, or is the interface made only through coding?
Thanks for the patience, guys.
If you want to use kivy I suggest that you learn Kv Language which is a simple language to design the UI for kivy.
.kv file example:
<MyWidget>:
label_widget: label_widget
Button:
text: 'Add Button'
on_press: root.add_widget(label_widget)
Button:
text: 'Remove Button'
on_press: root.remove_widget(label_widget)
Label:
id: label_widget
text: 'widget'
There is however a Kivy Designer which you can use to design the UI but it is still at alpha stage and not perfect yet.
WARNING: This project is at an unstable alpha stage and is not yet
suitable for general use. Contributions are welcome.
Kivy Designer is Kivy's tool for designing graphical user interfaces
(GUIs) from Kivy Widgets. You can compose and customize widgets, and
test them. It is completely written in Python using Kivy.
So if it doesn't do what you want, you can create a simple UI and have a look at the generated code so you get an idea of how the UI is written in python.

Kivy opening bubble with button

I want to be able to open the bubble with a button click.
I am kind of new to kivy.
Here's the code in the kivy file:
Button:
bubble:bubble.__self__
text:"Home"
on_release:self.show_bubble
Bubble:
id:bubble
size_hint: (None, None)
size: (150, 50)
pos_hint: {'x': 1, 'y': 1.7}
arrow_pos: 'bottom_mid'
orientation: 'horizontal'
BubbleButton:
text: "This is"
BubbleButton:
text: "a"
BubbleButton:
text: "Bubble"
Could anyone help?
Thanks.
You should follow the example shown here:
https://kivy.org/docs/api-kivy.uix.bubble.html
i.e. put the Bubble in a separate FloatLayout (for example) instead of inside the triggering Button
I have worked in KIVY for mobile-based application development. But let me tell you its quite a pain. If you just want to make interactive python programs that are not mobile based I think you should start with the Tkinter module.
KIVY is really ugly. I suggest porting to JAVA for mobile application development simply because it was born to do that.
We have a long way till everyone starts using python for mobile apps.

Categories

Resources