According to the kivy document, I can remove Window's border by Window.borderless = True
(https://kivy.org/doc/stable/api-kivy.core.window.html)
However, The problem is, it still shows the border when it starts up, then it gets removed in like 0.5 second. And it seems a bit weird to me
Is it possible to remove the border at the very beginning?
The problem is caused by first reading the Config and probably configured to be border and then read your configuration, so the solution in that case is to save it in the config, so a second load of the application will no longer watch that transition.
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.core.window import Window
from kivy.config import Config
Config.read("myapp.ini")
if Config.getint('graphics', 'borderless') == 0:
Config.set('graphics', 'borderless', '1')
Config.write()
Window.borderless = True
class MyApp(App):
def build(self):
return Widget()
if __name__ == '__main__':
MyApp().run()
Related
My simple label in kivy is very blurry, I just wanted to know how to make it look sharper?
Here's the code:
import kivy
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(text="Hello World")
if __name__ == '__main__':
MyApp().run()
Thanks.
The issue seems to be coming from you. On Windows 10, click the windows button/search, type ClearType. One of the options should say Adjust ClearType Text. Open that, and follow the wizard
I have an image located relative to the screen size with RelativeLayout. How can I get the global (/window) position of that image, so that I can detect if touch coordinates overlap the image?
this is my current implimentation:
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.image import Image
from kivy.uix.relativelayout import RelativeLayout
class mainApp(App):
def build(slef):
appRoot = FloatLayout()
relPos = RelativeLayout()
button = Image()
relPos.pos_hint = {"right":1,"top":1.5}
relPos.add_widget(button)
#attempting to print the coordinates of the Image in the window
print(relPos.to_parent(*button.pos))
return relPos
if __name__ == '__main__':
mainApp().run()
As you can see, I'm attempting to use to_parent to get the position relative to the parent. However, I don't think it works pos_hint.
I've also tried using AnchorLayout, and have had similar issues
Note: while I know I can use the window_size, allong with a bit of math, I would like a more robust solution that can handle more complex situations
Following a previous StackOverflow answer I made additions to one of the basic Kivy tutorial apps to position the window at the top left corner of the screen. This works as expected under Xorg, but not under Wayland/xwayland.
How do you change the Kivy window position when running under xwayland?
Code:
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.core.window import Window
class MyPaintWidget(Widget):
pass
class MyPaintApp(App):
def build(self):
# Works under Xorg, not under Wayland
Window.top = 0
Window.left = 0
return MyPaintWidget()
if __name__ == '__main__':
MyPaintApp().run()
Kivy does have Wayland support, but it may not be compiled-in. See setup.py. Also note that this will require SDL2 support to be compiled-in, as well:
# change both to "True"
c_options['use_wayland'] = False
c_options['use_sdl2'] = False
I'm writing a clock application (will eventually run on Raspberry Pi, but developing on Windows), and whenever a label updates the changed characters are drawn on top of the old ones, but the old one doesn't disappear.
It looks like this.
Here's my code:
main.py:
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock
from kivy.properties import StringProperty
from kivy.config import Config
import time
class RPiClock(BoxLayout):
timeString = StringProperty()
def __init__(self, **kwargs):
super(RPiClock, self).__init__(**kwargs)
def update(self, *args):
self.timeString = str(time.strftime("%I:%M:%S %p"))
class RPiClockApp(App):
def build(self):
Config.set('graphics', 'width', '800')
Config.set('graphics', 'height', '480')
appWindow = RPiClock()
Clock.schedule_interval(appWindow.update, 1)
return appWindow
if __name__ == "__main__":
RPiClockApp().run()
RPiClock.kv:
<RPiClock>
Label:
id: TimeLabel
text: root.timeString
font_size: '50sp'
What's causing these graphics to stick around?
I had a similar issue, try adding a colored canvas in the background -- in your case I would likely use a black rectangle that fills up your layout. It may solve your problem (it did for me).
I recently learnt about the Python framework kivy and started to follow the simple paint app tutorial. Now I want to save what was drawn as a .png file but instead of the colored dots it only exports the black background.
This is my code example:
import kivy
kivy.require("1.9.1")
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.graphics import Color, Ellipse, Line
class MyPaintWidget(Widget):
def on_touch_down(self,touch):
color=(0,0,1)
with self.canvas:
Color(*color)
d=30.
Ellipse(pos=(touch.x-d/2., touch.y-d/2.), size=(d,d))
class MyPaintApp(App):
def build(self):
parent=Widget()
self.painter=MyPaintWidget()
ssbtn=Button(text='Save')
ssbtn.bind(on_release=self.save_screenshot)
parent.add_widget(self.painter)
parent.add_widget(ssbtn)
return parent
def save_screenshot(self,obj):
self.painter.export_to_png("screenshot.png")
if __name__ == '__main__':
MyPaintApp().run()
What am I doing wrong? Thanks for your help.
You are missing one thing - Widget won't set its size and position automatically to whole Window size, but only to default ones i.e. pos = [0, 0] size = [100, 100] because Window != Layout and even adding it to something that doesn't inherit from a Layout won't make it better (Widget != Layout) which you can easily see if you look a that saved png (is too small).
self.painter=MyPaintWidget(size=[800,600])
will make the job for you if you plan to stay only on pc and only with the default Window size. If not, then use:
from kivy.core.window import Window
self.painter=MyPaintWidget(size=Window.size)
which seems to be more practical, yet you're still not there. An optimal solution would be using a Layout which does these things for you such as BoxLayout, GridLayout or some others.
And a perfect solution for you would be to use a StencilViewin a Layout, which when is placed won't take a screenshot of the whole canvas, but only the part you'd think it'll take i.e. the part sized as the Widget itself placed on its position.
Try drawing outside of the red box. Inspector will provide you with showing widgets in a color and other functions, so definitely try it as it was mentioned in the comments.
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.core.window import Window
from kivy.uix.stencilview import StencilView
from kivy.graphics import Color, Ellipse, Line, Rectangle
class MyPaintWidget(StencilView):
def on_touch_down(self,touch):
color=(0,0,1)
with self.canvas:
Color(*color)
d=30.
Ellipse(pos=(touch.x-d/2., touch.y-d/2.), size=(d,d))
class MyPaintApp(App):
def build(self):
parent=Widget()
self.painter=MyPaintWidget(size=[i/2.0 for i in Window.size])
with self.painter.canvas:
Color(1, 0, 0, 0.3)
Rectangle(pos=self.painter.pos, size=self.painter.size)
ssbtn=Button(text='Save')
ssbtn.bind(on_release=self.save_screenshot)
parent.add_widget(self.painter)
parent.add_widget(ssbtn)
return parent
def save_screenshot(self,obj):
self.painter.export_to_png("screenshot.png")
MyPaintApp().run()