如果你看第一个GridLayout下面有一个Image小部件。我试图让它移动到屏幕的右侧。任何帮助都是适当的。这是代码。我需要在右侧的小部件的id是id = image。我似乎无法移动它。
我提供了更多详细信息,因为stackoverflow需要它。我认为以上是非常详细的堆栈溢出,但是您的负责人在这里是更多文本。
谢谢大家。
from kivy.lang import Builder
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
Builder.load_string("""
<ClientScreen>:
GridLayout:
id: main_grid_layout
orientation: 'vertical'
cols: 1
Label:
id: name_label
text: '<NO MENU NAME>'
size_hint_y: None
size: self.texture_size
halign: 'left'
valign: 'center'
text_size: self.size
padding_x: 35
canvas.before:
Color:
rgb: .6, .6, .6
Rectangle:
pos: self.pos
size: self.size
Image:
id: image
pos_hint: {'right': 0.5}
ScrollView:
id: text_scroll_view
bar_width: 10
size: self.size
GridLayout:
id: text_grid_layout
orientation: 'vertical'
cols: 1
size_hint_y: None
height: self.minimum_height
ScrollView:
size: self.size
bar_width: 10
size_hint_y: 0.40
GridLayout:
id: action_grid_layout
# padding: [10, 10, 10, 10]
orientation: 'vertical'
cols: 1
size_hint_y: None
# row_default_height: 30
height: self.minimum_height
""")
class LoginScreen(Screen):
pass
class ClientScreen(Screen):
pass
class MyApp(App):
def build(self):
from kivy.core.window import Window
sm = ScreenManager()
sm.transition = NoTransition()
global CLIENT_SCREEN
LOGIN_SCREEN = LoginScreen(name='login')
CLIENT_SCREEN = ClientScreen(name='client')
sm.add_widget(LOGIN_SCREEN)
sm.add_widget(CLIENT_SCREEN)
sm.current = 'client'
Window.size = (300, 120)
self.title = 'xNemesis Client V0'
return sm
MyApp().run()
答案 0 :(得分:1)
在kv文件中,执行以下操作。有关详细信息,请参阅以下示例。
GridLayout:
替换为BoxLayout:
,因为GridLayout
与cols: 1
的展示与BoxLayout
orientation: 'vertical'
的展示类似。cols: 1
Image:
,添加size_hint_x: 0.4
pos_hint: {'right': 0.5}
替换为pos_hint: {'right': 1}
GridLayout没有名为orientation的属性。
from kivy.lang import Builder
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
Builder.load_string("""
<ClientScreen>:
BoxLayout:
id: main_grid_layout
orientation: 'vertical'
Label:
id: name_label
text: '<NO MENU NAME>'
size_hint_y: None
size: self.texture_size
halign: 'left'
valign: 'center'
text_size: self.size
padding_x: 35
canvas.before:
Color:
rgb: .6, .6, .6
Rectangle:
pos: self.pos
size: self.size
Image:
id: image
source: 'raspberrypi.png'
size_hint_x: 0.4
pos_hint: {'right': 1}
ScrollView:
id: text_scroll_view
bar_width: 10
size: self.size
GridLayout:
id: text_grid_layout
orientation: 'vertical'
cols: 1
size_hint_y: None
height: self.minimum_height
ScrollView:
size: self.size
bar_width: 10
size_hint_y: 0.40
GridLayout:
id: action_grid_layout
# padding: [10, 10, 10, 10]
orientation: 'vertical'
cols: 1
size_hint_y: None
# row_default_height: 30
height: self.minimum_height
""")
class LoginScreen(Screen):
pass
class ClientScreen(Screen):
pass
class MyApp(App):
def build(self):
from kivy.core.window import Window
sm = ScreenManager()
sm.transition = NoTransition()
global CLIENT_SCREEN
LOGIN_SCREEN = LoginScreen(name='login')
CLIENT_SCREEN = ClientScreen(name='client')
sm.add_widget(LOGIN_SCREEN)
sm.add_widget(CLIENT_SCREEN)
sm.current = 'client'
Window.size = (300, 120)
self.title = 'xNemesis Client V0'
return sm
MyApp().run()