Kivy 减小GridLayout中列的宽度
我有以下代码:Kivy 减小GridLayout中列的宽度,kivy,Kivy,我有以下代码: import kivy from kivy.app import App from kivy.uix.gridlayout import GridLayout from kivy.uix.image import Image from kivy.uix.label import Label from kivy.uix.button import Button class TedeGrid(GridLayout): def __init__(self, **kwargs)
import kivy
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.image import Image
from kivy.uix.label import Label
from kivy.uix.button import Button
class TedeGrid(GridLayout):
def __init__(self, **kwargs):
super(TedeGrid, self).__init__(**kwargs)
self.cols = 3
self.img = Image(source='sriyantra.png')
self.add_widget(self.img)
self.add_widget(Label(text="HELLO"))
self.inside = GridLayout()
self.inside.cols = 1
self.add_widget(self.inside)
self.next_button = Button(text="Next")
self.inside.add_widget(self.next_button)
self.prev_button = Button(text="Prev")
self.inside.add_widget(self.prev_button)
class Tedegraph(App):
def build(self):
return TedeGrid()
if __name__ == "__main__":
Tedegraph().run()
我想减少第三列的宽度,例如,第一列宽度的10%
更好的是,如果没有按钮,右边是一个小的点击区域(对
next
事件做出反应),左边是一个小的点击区域(对prev
事件做出反应)我会使用一个大的网格布局,我将放置较小的网格布局,并使用size\u hint=(宽度、高度)
如果您想要一个代码示例,请在代码中添加您使用的照片,以便我可以正确运行它吗?检查此项,我重新设计了您的代码,希望它有意义。这就是你想要的吗?如果你不明白如何改变某事,告诉我,我会为你改变/解释它
import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.image import Image
from kivy.uix.label import Label
from kivy.config import Config
from kivy.uix.button import Button
class Tedegraph(App):
def build(self): # I will add everything here
# For your example, it's better to use boxlayout, you don't want a table/grid like pattern, right?
mainbox = BoxLayout(orientation="horizontal", # Create the main box layout and make it horizontal
spacing=15, # Add spacing between widgets
padding=5) # And padding on the sides
mainbox.add_widget(Button(text="Prev", # Add the prev button
font_size="17dp", # set font size
size_hint=(.3, .2), # make the button smaller
pos_hint={"center_x":0.5, # Center it on the x
"center_y":0.5}, # And on the y
on_press=self.prevscreen)) # Attach a button function
mainbox.add_widget(Image(source='sriyantra.png')) # Add your image after the button
mainbox.add_widget(Label(text="HELLO")) # And add the text
mainbox.add_widget(Button(text="Next", # Add the next button and set the same parameters for the next button
font_size="17dp",
size_hint=(.3, .2),
pos_hint={"center_x":0.5,
"center_y":0.5},
on_press=self.nextscreen)) # And change the button press function
return mainbox
# I created the functions for you
def nextscreen(self, *args):
print("Clicked Next")
# Here you can write the code that you want to do when the prev button is pressed
def prevscreen(self, *args):
print("Clicked Prev")
# Here you can write the code that you want to do when the next button is pressed
if __name__ == "__main__":
Tedegraph().run()
谢谢,这是照片。请问,您如何在屏幕底部放置一个小部件(组合框)?我不希望它占据右边的空间,这是默认位置,我想把它绑定到底部。谢谢。@xraf您可以使用垂直框布局而不是水平框布局,在这种情况下:mainbox=BoxLayout(orientation=“horizontal”,space=15,padding=5)