画中的空间通过BoxLayout的闲置

时间:2019-02-02 09:17:19

标签: kivy

我想制作一个GUI,它可以让我在底部输入文本,也可以让我在屏幕的其余部分绘图。我能够使用BoxLayout在窗口的底部制作文本框和按钮,但是我我不能够使用的剩余空间进行绘图。这是我的代码的输出:The output

下面是我的代码

import sys
import os
import kivy
kivy.require("1.10.0")
from kivy.app import App
from kivy.core.window import Window
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.widget import Widget
from kivy.graphics import Line,Ellipse
from kivy.config import Config

Config.set('input', 'mouse', 'mouse,multitouch_on_demand')

class Draw(Widget):
    def on_touch_down(self,touch):
        print(touch)
        with self.canvas:
            touch.ud["line"]=Line(points=(touch.x,touch.y))
    def on_touch_move(self,touch):
        print(touch)
        with self.canvas:
            touch.ud["line"].points +=(touch.x,touch.y)
    def on_touch_up(self,touch):
        print("released mouse",touch)


class MAP(BoxLayout):    
    def __init__(self, **kwargs):
        super(MAP, self).__init__(**kwargs)        
        self.S=TextInput(multiline=False, size_hint=(800,0.05))
        self.add_widget(self.S)
        self.b=Button(text="OK",size_hint=(200,0.05))
        self.add_widget(self.b)
    Draw()






class GUI(App):
    def build(self):
        return MAP()

if __name__ == '__main__':
    print(Window.size)
    GUI().run()

1 个答案:

答案 0 :(得分:1)

您的prefix = {} prefix[guild.id] = "@" 小部件会绘制图形,但永远不会将其添加到显示中。尝试将Draw类更改为:

MAP

请注意,流浪class MAP(BoxLayout): def __init__(self, **kwargs): super(MAP, self).__init__(**kwargs) self.S=TextInput(multiline=False, size_hint=(800,0.05)) self.add_widget(self.S) self.b=Button(text="OK",size_hint=(200,0.05)) self.add_widget(self.b) self.draw = Draw() self.add_widget(self.draw) # Draw() 已被注释掉(它没有做任何事情),并且Draw()小部件现已添加到Draw小部件中。