Kivy App size fixed in full screen windowed - python

I've made a windows app with Kivy and I want to set the size of the window to a fixed size which is full-screen windowed and I can't figure it out.
i've tried this method:
from kivy.core.window import Window
Window.size = (1920, 1080)
Window.fullscreen = True
It makes the app full screen but not full screen windowed. Does anyone have a solution for this please?

Config.set determines the size of the window and should be indicated at the very beginning of the script. For more information check https://kivy.org/doc/stable/api-kivy.config.html
from kivy.config import Config
Config.set('graphics', 'width', '1920')
Config.set('graphics', 'height', '1080')

Related

How do I get the kivy Window.softinput_mode = 'below_target' to move the TextInput box above the virtual keyboard?

I'm using python 3.8.6 and kivy 2.1.0.
When the text input box gets focus, the keyboard pops up and covers the TextInput box. I've added the 2 lines below to force the keyboard to be below the target TextInput box, but it does not work as expected.
Window.keyboard_anim_args = {"d":.2,"t":"linear"}
Window.softinput_mode = "below_target"
I've also tried 'pan' and 'resize'. The code runs with no errors, but none of these settings has any effect on the behavior, so I'm sure I'm missing something obvious, but it's not obvious to me:-(. Any help is greatly appreciated. The full code follows:
from kivy.app import App
from kivy.core.window import Window
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.config import Config
Window.keyboard_anim_args = {"d":.2,"t":"linear"}
Window.softinput_mode = "below_target"
#Window.softinput_mode = 'pan'
#Window.softinput_mode = 'resize'
class ClearApp(App):
def build(self):
self.box = BoxLayout(orientation='horizontal', spacing=10)
self.txt = TextInput(hint_text='Write here',
keyboard_mode='auto',
size_hint=(.5,.1))
self.btn = Button(text='Clear All',
on_press=self.clearText, size_hint=(.1,.1))
self.box.add_widget(self.txt)
self.box.add_widget(self.btn)
return self.box
def clearText(self, instance):
self.txt.text = ''
'''
if Config:
_is_desktop = Config.getboolean('kivy', 'desktop')
_keyboard_mode = Config.get('kivy', 'keyboard_mode')
if _is_desktop:
Config.set('kivy', 'keyboard_mode','system')
Config.write()
else:
Config.set('kivy', 'keyboard_mode','systemanddock')
Config.write()
'''
Config.set('kivy', 'keyboard_mode','dock')
Config.write()
ClearApp().run()
Use import Config before import App
which help you to focus and show your keyboard in the UI
for eg.
from kivy.config import Config
from kivy.app import App
use these these line in your code
This function is available only in the master kivy version. so in your buildozer.spec file in the requirements put kivy==master when you are adding kivy to the requirements

How do I set the orientation for an application in Kivy?

I have a 1366 x 768p display, and I'm making an application on it using Kivy. However, I'm using
the display in a vertical orientation. How do I make it so that my application displays In vertical orientation?
kivy.require('1.8.0')
from kivy.uix.label import Label
from kivy.uix.app import App
class SimpleKivy(App):
def build(self):
return Label(text = "TEST")
if __name__ = "__main__":
SimpleKivy().run()
Orientation can be set in buildozer.spec
# (str) Supported orientation (one of landscape, sensorLandscape, portrait or all)
orientation = portrait
also for a better representation on desktop you can use kivy.Config from
Kivy docs
from kivy.config import Config
Config.set('graphics', 'position', 'custom')
Config.set('graphics', 'left', 0)
Config.set('graphics', 'top', 0)
Config.set('graphics', 'height', 1366)
Config.set('graphics', 'width', 768)
Also you should use the latest Kivy Version 1.11.1 unless you do this for a specific reason.

Is it possible to change a Kivy app taskbar icon?

I have a kivy app, here's the code:
class ComicNotificatorApp(App):
def build(self):
Window.size = (300, 300)
self.title = 'Comics Notificator'
self.icon = 'assets/icon.png'
return Label(text=to_display)
and I'd like to change the taskbar icon of the app
and while I'm at it, how can I change the size of the window to automatically fit the size of the label, as opposed to setting it manually?
Thank you!
stackoverflow question <-- this link mention a similar question and I think this may help
kivy doc for your ref about kivy config object
and I only know how to change the window's icon but not the task bar one
...
class MyKivyApp(App):
def build(self):
self.title = 'window's title'
self.icon = <icon>: str <----
...
the taskbar one maybe you can change it when packaging
how can I change the size of the window to automatically fit the size of the label
maybe you can try to use the kivy.config.Config.set() , if I get it correctly , you want to set the size of the window == size of label ? if so then set the size of the label first, then use kivy.config.Config.set('graphics', 'width', <size>: str) kivy.config.Config.set('graphics', 'height', <size>: str)
# I assume you won't change the label size after starting the kivy screen 😅
import kivy
kivy.config.Config.set('graphics', 'width', <label_width>: str)
kivy.config.Config.set('graphics', 'width', <label_height>: str)
...
because the config have to set at the very beginning , before the kivy window is created
e.g.
import kivy
# set config here
# import another stuff
hope this help : )
A bit late but for your main question Is it possible to change a kivy app taskbar icon, no it isn't possible to change the taskbar icon if you are running the app as a script, not an executable of some kind. However, the taskbar icon will automatically sync with your window icon when run as an executable(by packaging your app using pyinstaller or py2exe, anything like that could work)

Kivy image not showing

Im working on a basic app using python and kivy and im trying to import an image which I'm basically going to use as a splash screen of sorts but for some reason I couldn't get it to work so I created a .py file and wrote some very simple code to try to get it to work:
from kivy.app import App
from kivy.uix.label import Label
from kivy.core.window import Window
Window.size = (360, 640)
class ImageTestApp(App):
def build(self):
label = Label(source="image.jpg")
return label
if __name__ == "__main__":
ImageTestApp().run()
The image is in the same directory of the .py file and the name of the image is exactly the same, I even made the window size the same as the image size and tried .PNG but nothing worked 😖
Label does not have an attribute called source. You should change Label to Image, and it will works. Please refer to example below for details.
Example
main.py
from kivy.app import App
from kivy.uix.image import Image
from kivy.core.window import Window
Window.size = (360, 640)
class ImageTestApp(App):
def build(self):
return Image(source="image.jpg")
if __name__ == "__main__":
ImageTestApp().run()
Output

Setting kivy window size not working

I follwed this stackoverflow question, but neither alternatives worked.
This is my code:
from kivy.app import App
from kivy.uix.label import Label
from kivy.core.window import Window
class MyApp(App):
def build(self):
return Label(text='text')
if __name__ == '__main__':
Window.size = (1366, 768)
MyApp().run()
Sometimes the size works, Kivy creates a screen with size 800x600 then changes it to 1366x768. And sometimes Kivy creates a screen with size 800x600 then changes it to 1366x768, but then back to 800x600.
And if I change my code to:
from kivy.app import App
from kivy.uix.label import Label
from kivy.core.window import Window
from kivy.config import Config
Config.set('graphics', 'width', '200')
Config.set('graphics', 'height', '200')
class MyApp(App):
def build(self):
return Label(text='text')
if __name__ == '__main__':
MyApp().run()
With this code, nothing happens on my screen. I'm using Kivy v1.9.2-dev0. What I should do to fix it?
Put the Config settings before all the other imports - it's too late after importing Window, as the config has already been accessed to determine its initial size and your new settings are ignored.
Make your window non-resizable
from kivy.config import Config
Config.set('graphics','resizable',0)
set the window size
from kivy.core.window import Window
Window.size = (600, 500)
see example at https://kivyapps.wordpress.com/video-streaming-using-kivy-and-python/

Categories