前提・実現したいこと
Python Kivyを用いて、GUIに入力した文字がそのまま同じウインドウに出力されるようなプログラムを作成しています。
発生している問題
下の画像はプログラムを実行したときのウィンドウですが、右上の白いボックスに文字を入力すると、右下の黒い部分に文字が出力されるようなものを作成したいです。
しかし、現状では、右下ではなく、左下の角に出力されるようになっています。
どのように修正するとよいのでしょうか。
該当のソースコード
#-*- coding: utf-8 -*- from kivy.config import Config Config.set('graphics', 'width', '1024') Config.set('graphics', 'height', '768') Config.set('graphics', 'resizable', False) from kivy.app import App from kivy.uix.widget import Widget from kivy.uix.label import Label from kivy.properties import StringProperty, ListProperty from kivy.core.text import LabelBase, DEFAULT_FONT from kivy.resources import resource_add_path class TextWidget(Widget): text = StringProperty() def __init__(self, **kwargs): super(TextWidget, self).__init__(**kwargs) pass def test(self): num = self.ids["number"].text self.add_widget(Label(text=num)) pass class MylayoutApp(App): def __init__(self, **kwargs): super(MylayoutApp, self).__init__(**kwargs) self.title = 'test' def build(self): return TextWidget() if __name__ == '__main__': MylayoutApp().run()
kvファイル
TextWidget: <TextWidget>: BoxLayout: orientation: 'vertical' size: root.size BoxLayout: orientation: 'horizontal' Label: text: "Input" TextInput: id: number BoxLayout: orientation: 'horizontal' Label: text: "Output" Label: on_touch_down: root.test()
補足情報(FW/ツールのバージョンなど)
MacBook Pro (macOS High Sierra 10.13.6)
Python 3.6.1
Cython 0.28.5
Kivy 1.10.1
修正後の実行画面
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/11 14:34
2018/10/12 12:37
2018/10/14 01:45
2018/10/15 12:33
2018/10/17 00:17