Program started from PyCharm not looking like in Kivy-Examples - python

I build tree of widgets in kivy-examples and all looking fine. But after i copy a code into pycharm i got something else. What i did bad? I have no idea how to fix it and what could be a reason of this...
<MyGrid>
BoxLayout:
orientation: 'vertical'
padding: 5
spacing: 5
BoxLayout:
text: "Button 1"
size_hint: 1, .08
Button:
BoxLayout:
size_hint: 1, .3
BoxLayout:
orientation: 'horizontal'
GridLayout:
cols: 2
Button:
Button:
Button:
Button:
Button:
Button:
Button:
Button:
GridLayout:
cols: 2
Button:
Button:
Button:
Button:
Button:
Button:
Button:
Button:
Button:
Button:
BoxLayout:
orientation: 'vertical'
Button:
GridLayout:
cols: 2
Button:
Button:
Button:
Button:
BoxLayout:
Button:
Button:
Button:
BoxLayout:
size_hint: 1, .5
Button:
BoxLayout:
size_hint: 1, .12
Button:
how it look in kivy-examples
and in pycharm

In your pycharm version the root widget is probably not a layout, so the top level BoxLayout has the default size of (100, 100). Presumably this is the MyGrid from your rule. Make MyGrid inherit from BoxLayout.

Related

Create a recycle view(Gridlayout) inside a Boxlayout kivy

I need all the elements of my FirsWindow, put them in a recycleview. I'm thinking to do it from RecycleGridLayout instead of GridLayout, but I don't how to really apply it in the code. It's necesary that the GridLayout or RecycleGridLayout have cols:4, I think it's not necessary upload my py.file but I'm not sure. please I need help on this. thanks in advance.
kv.file
<FirstWindow>:
name: "Catalogue"
BoxLayout:
id: Boxmain
orientation: "vertical"
#size: root.width, root.height
#size_hint: 1, None
#height: 300
#padding: 50
spacing: 50
size: root.height, root.width
GridLayout:
cols: 4
padding: 4
Label:
text: "Items"
#font_size: 25
Label:
text: "Number"
Label:
text: "Price"
Label:
text: "Add to Cart"
Label:
text: "Tornillos"
text_size: self.size
halign: 'center'
valign: 'bottom'
Image:
id: image_tornillos
allow_stretch: True
keep_ratio: True
size_hint: 0.2,0.2
width: 60
height: 80
#pos_hint: {'center_x':1, 'center_y':1}
source: "images/tornillo.png"
center_x: self.parent.center_x
center_y: self.parent.center_y+10
TextInput:
id: input_tornillo
text: ""
halign: "right"
font_size: 18
multiline: True
#size_hint: (1, .15)
Label:
text: "0.0"
Button:
id: shopping1
#text: "Hello"
#font_size: 32
allow_stretch: True
keep_ratio: True
size_hint: .25,.30
pos_hint: {'center_x':0.5, 'center_y':0.5}
background_color: 0,0,0,0
#on_press: root.press_on()
#on_release: root.press_off()
on_press: root.ids.Shoppingcart1.source= root.var2
on_release: root.ids.Shoppingcart1.source= root.var1
Image:
id: Shoppingcart1
allow_stretch: True
keep_ratio: True
size_hint: 0.5,0.5
width: 60
height: 60
pos_hint: {'center_x':0.5, 'center_y':0.5}
source: root.var1
center_x: self.parent.center_x
center_y: self.parent.center_y
#------------------------
Button:
text:"lala"
Button:
text:"lal2"
Button:
text:"lale"
Button:
text:"lal5"
Button:
text:"lala"
Button:
text:"lal54"
Button:
text:"lala"
#------------------------------------------------------------

How to remove the space between two BoxLayouts in Kivy?

I state that I have already read the answers of other users to this question but none of them helped me. I'm trying to program a calculator in python with the kivy GUI interface,he problem is that i can't remove that space highlighted in red in the attached photo down here. I have already tried with: size_hint: None,None and size:root.size[0], "5dp" to scale the BoxLayouts but it doesn't worked
[1]: https://i.stack.imgur.com/y1ZwF.png
BoxLayoutExample:
<BoxLayoutExample>:
orientation: "vertical"
Label:
text: "0"
font_size: "30dp"
BoxLayout:
orientation: "horizontal"
Button:
text: "7"
size_hint: .1, .3
Button:
text: "4"
size_hint: .1, .3
Button:
text: "1"
size_hint: .1, .3
BoxLayout:
orientation: "horizontal"
Button:
text: ","
size_hint: .1, .3
Button:
text: "0"
size_hint: .1, .3
Button:
text: "="
size_hint: .1, .3
Your problem is that you are setting size_hint of the Buttons relative to its parent BoxLayout. So in effect your BoxLayout's are taking up 1/3 of the available space (because there are three widgets in BoxLayoutExample.
Here is how to fix it:
<BoxLayoutExample>:
orientation: "vertical"
Label:
text: "0"
font_size: "30dp"
size_hint: 1, .8
BoxLayout:
orientation: "horizontal"
size_hint: 1, .1
Button:
text: "7"
Button:
text: "4"
Button:
text: "1"
BoxLayout:
orientation: "horizontal"
size_hint: 1, .1
Button:
text: ","
Button:
text: "0"
Button:
text: "="
Adjust the size of the Label and the BoxLayout accordingly

kivy VideoPlayer: Video does not return to its original size after full screen mode

When I double click on the video, it goes full screen, but if I double click on it again, it doesn't go back to normal. However, the rest of the window elements are partially visible. The part of my .kv code responsible for the VideoPlayer is given below:
<VideosWindow>:
name: 'vids'
FloatLayout:
FileChooserListView:
id:chooser
path: root.get_files_list()
canvas.before:
Color:
rgb: .4, .5, .5
Rectangle:
pos: self.pos
size: self.size
on_selection: root.select(chooser.selection)
size_hint: (.9, .15)
pos_hint: {'x':.05, 'y':.8}
VideoPlayer:
id:vid
options: {'eos':'loop'}
size_hint: (.9, .7)
pos_hint: {'x':.05, 'y':.05}
Button:
size_hint_y: 0.3
height: 48
text: "open"
disabled: not chooser.selection
on_release: root.select(chooser.selection)
size_hint: (.45, .05)
pos_hint: {'x':.05, 'y':.00}
Button:
text: 'Go Back'
color: (1,1,1,1)
background_normal:''
background_color: (0.3,0.6,0.7,1)
on_release:
vid.state = 'pause'
app.root.current = 'saved_files'
size_hint: (.45, .05)
pos_hint: {'x':.50, 'y':.00}
VideosWindow class code:
class VideosWindow(Screen):
def get_files_list(self):
files = os.sep.join([my_folder,'mp4'])
return files
def select(self, filename):
self.ids.vid.source = filename[0]
self.ids.vid.state = 'play'
The screenshots of my program before and after I go fullscreen mode:
before
after
Solved this issue by adding VideoPlayer widget to the GridLayout. Now .kv code looks like this:
<VideosWindow>:
name: 'vids'
FloatLayout:
FileChooserListView:
id:chooser
path: root.get_files_list()
canvas.before:
Color:
rgb: .4, .5, .5
Rectangle:
pos: self.pos
size: self.size
on_selection: root.select(chooser.selection)
size_hint: (.9, .15)
pos_hint: {'x':.05, 'y':.8}
GridLayout:
cols:1
size_hint: (.9, .7)
pos_hint: {'x':.05, 'y':.05}
VideoPlayer:
id:vid
options: {'eos':'loop'}
Button:
size_hint_y: 0.3
height: 48
text: "open"
disabled: not chooser.selection
on_release: root.select(chooser.selection)
size_hint: (.45, .05)
pos_hint: {'x':.05, 'y':.00}
Button:
text: 'Go Back'
color: (1,1,1,1)
background_normal:''
background_color: (0.3,0.6,0.7,1)
on_release:
vid.state = 'pause'
app.root.current = 'saved_files'
size_hint: (.45, .05)
pos_hint: {'x':.50, 'y':.00}
Don't know if it is good decision but it works.

Set global font size for all children in box layout in Kivy

I've got three buttons in a box layout in Kivy. I want each of them to have the same fontsize. Is there a way to specify the font size for all widgets within a box layout, instead of having to define the font size in the child widgets?
This box layout's part of the .kv file looks like this
BoxLayout:
id: action_buttons
orientation: "horizontal"
size_hint: 1, None
height: "100dp"
Button:
id: cust_query
text: "Send Custom Query"
font_size: 24
Button:
id: man_query
text: "Manually Check Tables"
font_size: 24
ToggleButton:
id: sched_query
text: "Start Query Schedule"
on_state: root.schedule_switch_state(self)
font_size: 24
Is there a way to do this more like so:
BoxLayout:
id: action_buttons
orientation: "horizontal"
size_hint: 1, None
height: "100dp"
font_size: 24
Button:
id: cust_query
text: "Send Custom Query"
Button:
id: man_query
text: "Manually Check Tables"
ToggleButton:
id: sched_query
text: "Start Query Schedule"
on_state: root.schedule_switch_state(self)
I think I found a solution : font_size: self.parent.font_size
in *.kv
#:kivy 2.0.0
<Main>:
BoxLayout:
id: myboxlayout
orientation: "horizontal"
size: root.size
font_size: 24
Button:
text: "Button 1"
font_size: self.parent.font_size
Button:
text: "Button 2"
font_size: self.parent.font_size
first set a font size for the boxlayout
then point the fontsize of the button to their parent's fontisze
// hope this help : )

kivy image button size

My goal is to have Buttons which are completely filled with an image. My screen is split in half. On the right hand side I would like to have nine buttons each completely filled with a different image, all buttons with same dimensions. I would like to reshape those image to fit the button, so the ratio would possibly have to change.
This is how my GUI looks right now. The images do not fit the buttons
I tried several adjustments in my kv file, but right now I am stuck.
This is my kv file.
RadioRoot:
<RadioRoot#BoxLayout>:
BoxLayout:
BoxLayout:
BoxLayout:
orientation: "vertical"
Label:
size_hint_y: 4
text: "info about radio"
BoxLayout:
size_hint_y: 1
BoxLayout:
orientation: "vertical"
BoxLayout:
Button:
text: "Previous"
on_press: root.previous()
Button:
text: "Play/Stop"
on_press: root.play_stop()
Button:
text: "Next"
on_press: root.next()
Button:
size_hint_y: 1
text: "Shutdown"
on_press: root.shutdown()
BoxLayout:
BoxLayout:
orientation: "vertical"
BoxLayout:
Button:
text: "Channel1"
on_press: root.channel(1)
#size_hint_y: None
#size_hint_x: None
Image:
source: 'swr3.png'
size_hint_y: None
size_hint_x: None
y: self.parent.y + .5* self.parent.height -.5 * self.parent.width/self.image_ratio
x: self.parent.x
#heigth: self.parent.width/self.image_ratio
#heigth: self.parent.height
width: self.parent.width
keep_ratio: True
allow_stretch: True
Button:
text: "Channel2"
on_press: root.channel(2)
Image:
source: 'flux.png'
width: self.parent.width
size_hint_y: None
size_hint_x: None
y: self.parent.y + .5* self.parent.height -.5 * self.parent.width/self.image_ratio
x: self.parent.x
keep_ratio: True
allow_stretch: True
Button:
text: "Channel3"
on_press: root.channel(3)
BoxLayout:
Button:
text: "Channel4"
on_press: root.channel(4)
Button:
text: "Channel5"
on_press: root.channel(5)
Button:
text: "Channel6"
on_press: root.channel(6)
BoxLayout:
Button:
text: "Channel7"
on_press: root.channel(7)
Button:
text: "Channel8"
on_press: root.channel(8)
Button:
text: "Channel9"
on_press: root.channel(9)
This is the corresponding python file
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
class PhilippsRadioApp(App):
pass
class RadioRoot(BoxLayout):
def previous(self):
print("Previous")
def play_stop(self):
print("Play/Stop")
def next(self):
print("Next")
def shutdown(self):
print("Shutdown")
def channel(self, num):
print("Channel")
if __name__ == '__main__':
PhilippsRadioApp().run()
In your Image tag you are using width but not size ...
try:
Image:
...
size: self.parent.size #I think you can remove the size hints since they don't add anything...
stretch: True #keep this one as well :)

Categories

Resources