Python KIVY:TextInput不允许我在它里面写东西
我正在制作一个需要文本输入的应用程序,目的是创建一个图形外壳,但没关系。当我试图在文本输入中写入任何内容时,什么也没有发生,我无法在其中写入内容。 这是我的密码。如果您想测试它以查看文本输入,您必须启动应用程序,然后单击右侧的一个>绿色按钮,然后单击Python3 shell .py: .kv:Python KIVY:TextInput不允许我在它里面写东西,python,kivy,Python,Kivy,我正在制作一个需要文本输入的应用程序,目的是创建一个图形外壳,但没关系。当我试图在文本输入中写入任何内容时,什么也没有发生,我无法在其中写入内容。 这是我的密码。如果您想测试它以查看文本输入,您必须启动应用程序,然后单击右侧的一个>绿色按钮,然后单击Python3 shell .py: .kv: 当我运行你的代码时,我得到了关于多个同名屏幕的警告。我相信这是因为您运行Builder.load_filegui.kv并忽略返回的主屏幕。所以我重写了你的gui.kv文件: #:kivy 1.10.0
当我运行你的代码时,我得到了关于多个同名屏幕的警告。我相信这是因为您运行Builder.load_filegui.kv并忽略返回的主屏幕。所以我重写了你的gui.kv文件:
#:kivy 1.10.0
<Main>:
name: "main_screen"
id: main_screen
GridLayout:
id: glayout
cols: 3
Button:
size: (8,8)
size_hint_x: None
text: "|"
background_color: (0,1,0,1)
on_press: main_screen.isShownMenu = not main_screen.isShownMenu
BoxLayout:
id: menu
orientation: 'vertical'
width: 120 if main_screen.isShownMenu else 0
height: 120
size_hint: (None, 1)
opacity: 1 if main_screen.isShownMenu else 0
Button:
text: "Menu button"
Button:
text: "Menu button"
Button:
text: "Menu button"
Button:
text: "Menu button"
ScrollView:
id: view
size_hint: 1, 1
<Connection>:
name: "connection_screen"
id: connection_screen
GridLayout:
cols: 3
Button:
size: (8,8)
size_hint: (None, 1)
text: "|"
background_color: (0,1,0,1)
on_press: connection_screen.isShownMenu = not connection_screen.isShownMenu
BoxLayout:
id: menu
orientation: 'vertical'
width: 120 if connection_screen.isShownMenu else 0
height: 120
size_hint: (None, 1)
opacity: 1 if connection_screen.isShownMenu else 0
Button:
text: "Menu button"
Button:
text: "Menu button"
Button:
text: "Menu button"
Button:
text: "Menu button"
BoxLayout:
id: blayout
orientation: 'vertical'
GridLayout:
id: conlayout
cols: 2
size: (50, 50)
size_hint: (1, None)
Button:
size: (50, 50)
size_hint: (None, None)
text: "<"
on_press: connection_screen.manager.current = "main_screen"
Button:
id: title
size: (50, 50)
size_hint: (1, None)
background_color: (0, 0, 1, 1)
color: (1, 1, 1, 1)
text: ""
BoxLayout:
spacing: 10
padding: 10
AnchorLayout:
anchor_x: 'left'
anchor_y: 'top'
Button:
size: (80, 80)
size_hint: (1, None)
text: "Python 3 shell"
on_press: connection_screen.manager.current = "py3shell_screen"
AnchorLayout:
anchor_x: 'right'
anchor_y: 'top'
Button:
size: (80, 80)
size_hint: (1, None)
text: "System shell"
<Py3Shell>:
name: "py3shell_screen"
id: py3shell_screen
GridLayout:
cols: 3
Button:
text: "<"
size: (50, 50)
size_hint: (None, None)
Button:
text: "Python 3 shell"
size: (50, 50)
size_hint: (1, None)
Button:
text: "X"
size: (50, 50)
size_hint: (None, None)
background_color: (1, 0, 0, 1)
BoxLayout:
GridLayout:
cols: 3
size: (50, 50)
size_hint: (1, None)
Label:
text: "prompt $>"
size: (75, 50)
size_hint: (None, None)
TextInput: # <----------------------------------------- here
id: ti
height: 50
size_hint: (1, None)
background_color: (1, 1, 1, 1)
color: (1, 1, 1, 1)
Button:
text: ">"
size: (50, 50)
size_hint: (None, None)
background_color: (0, 1, 0, 1)
非常感谢,它帮了很多忙!
#:kivy 1.10.0
<SM>:
Main:
name: "main_screen"
id: main_screen
Connection:
name: "connection_screen"
id: connection_screen
Py3Shell:
name: "py3shell_screen"
id: py3shell_screen
<Main>:
GridLayout:
cols: 3
Button:
size: (8,8)
size_hint: (None, 1)
text: "|"
background_color: (0,1,0,1)
on_press: root.isShownMenu = not root.isShownMenu
BoxLayout:
id: menu
orientation: 'vertical'
width: 120 if root.isShownMenu else 0
height: 120
size_hint: (None, 1)
opacity: 1 if root.isShownMenu else 0
Button:
text: "Menu button"
Button:
text: "Menu button"
Button:
text: "Menu button"
Button:
text: "Menu button"
ScrollView:
id:view
<Connection>:
GridLayout:
cols: 3
Button:
size: (8,8)
size_hint: (None, 1)
text: "|"
background_color: (0,1,0,1)
on_press: root.isShownMenu = not root.isShownMenu
BoxLayout:
id: menu
orientation: 'vertical'
width: 120 if root.isShownMenu else 0
height: 120
size_hint: (None, 1)
opacity: 1 if root.isShownMenu else 0
Button:
text: "Menu button"
Button:
text: "Menu button"
Button:
text: "Menu button"
Button:
text: "Menu button"
BoxLayout:
orientation: 'vertical'
GridLayout:
cols: 2
size: (50, 50)
size_hint: (1, None)
Button:
size: (50, 50)
size_hint: (None, None)
text: "<"
on_press: root.manager.current = "main_screen"
Button:
id: title
size: (50, 50)
size_hint: (1, None)
background_color: (0, 0, 1, 1)
color: (1, 1, 1, 1)
text: ""
BoxLayout:
spacing: 10
padding: 10
AnchorLayout:
anchor_x: 'left'
anchor_y: 'top'
Button:
size: (80, 80)
size_hint: (1, None)
text: "Python 3 shell"
on_press: root.manager.current = "py3shell_screen"
AnchorLayout:
anchor_x: 'right'
anchor_y: 'top'
Button:
size: (80, 80)
size_hint: (1, None)
text: "System shell"
<Py3Shell>:
GridLayout:
cols: 3
Button:
text: "<"
size: (50, 50)
size_hint: (None, None)
Button:
text: "Python 3 shell"
size: (50, 50)
size_hint: (1, None)
Button:
text: "X"
size: (50, 50)
size_hint: (None, None)
background_color: (1, 0, 0, 1)
BoxLayout:
GridLayout:
cols: 3
size: (50, 50)
size_hint: (1, None)
Label:
text: "prompt $>"
size: (75, 50)
size_hint: (None, None)
TextInput: # <----------------------------------------- here
size: (50, 50)
size_hint: (1, None)
background_color: (.1, .1, .1, 1)
color: (1, 1, 1, 1)
Button:
text: ">"
size: (50, 50)
size_hint: (None, None)
background_color: (0, 1, 0, 1)
#:kivy 1.10.0
<Main>:
name: "main_screen"
id: main_screen
GridLayout:
id: glayout
cols: 3
Button:
size: (8,8)
size_hint_x: None
text: "|"
background_color: (0,1,0,1)
on_press: main_screen.isShownMenu = not main_screen.isShownMenu
BoxLayout:
id: menu
orientation: 'vertical'
width: 120 if main_screen.isShownMenu else 0
height: 120
size_hint: (None, 1)
opacity: 1 if main_screen.isShownMenu else 0
Button:
text: "Menu button"
Button:
text: "Menu button"
Button:
text: "Menu button"
Button:
text: "Menu button"
ScrollView:
id: view
size_hint: 1, 1
<Connection>:
name: "connection_screen"
id: connection_screen
GridLayout:
cols: 3
Button:
size: (8,8)
size_hint: (None, 1)
text: "|"
background_color: (0,1,0,1)
on_press: connection_screen.isShownMenu = not connection_screen.isShownMenu
BoxLayout:
id: menu
orientation: 'vertical'
width: 120 if connection_screen.isShownMenu else 0
height: 120
size_hint: (None, 1)
opacity: 1 if connection_screen.isShownMenu else 0
Button:
text: "Menu button"
Button:
text: "Menu button"
Button:
text: "Menu button"
Button:
text: "Menu button"
BoxLayout:
id: blayout
orientation: 'vertical'
GridLayout:
id: conlayout
cols: 2
size: (50, 50)
size_hint: (1, None)
Button:
size: (50, 50)
size_hint: (None, None)
text: "<"
on_press: connection_screen.manager.current = "main_screen"
Button:
id: title
size: (50, 50)
size_hint: (1, None)
background_color: (0, 0, 1, 1)
color: (1, 1, 1, 1)
text: ""
BoxLayout:
spacing: 10
padding: 10
AnchorLayout:
anchor_x: 'left'
anchor_y: 'top'
Button:
size: (80, 80)
size_hint: (1, None)
text: "Python 3 shell"
on_press: connection_screen.manager.current = "py3shell_screen"
AnchorLayout:
anchor_x: 'right'
anchor_y: 'top'
Button:
size: (80, 80)
size_hint: (1, None)
text: "System shell"
<Py3Shell>:
name: "py3shell_screen"
id: py3shell_screen
GridLayout:
cols: 3
Button:
text: "<"
size: (50, 50)
size_hint: (None, None)
Button:
text: "Python 3 shell"
size: (50, 50)
size_hint: (1, None)
Button:
text: "X"
size: (50, 50)
size_hint: (None, None)
background_color: (1, 0, 0, 1)
BoxLayout:
GridLayout:
cols: 3
size: (50, 50)
size_hint: (1, None)
Label:
text: "prompt $>"
size: (75, 50)
size_hint: (None, None)
TextInput: # <----------------------------------------- here
id: ti
height: 50
size_hint: (1, None)
background_color: (1, 1, 1, 1)
color: (1, 1, 1, 1)
Button:
text: ">"
size: (50, 50)
size_hint: (None, None)
background_color: (0, 1, 0, 1)
import kivy
kivy.require('1.10.0')
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import BooleanProperty, ObjectProperty
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.clock import Clock
from functools import partial
from kivy.config import Config
Config.set('graphics', 'minimum_width', 400)
Config.set('graphics', 'minimum_height', 300)
Config.write()
class Main(Screen):
isShownMenu = BooleanProperty(True)
view = ObjectProperty(None)
def __init__(self, **kwargs):
super(Main, self).__init__(**kwargs)
Clock.schedule_once(self.create_scrollview)
def create_scrollview(self, dt):
base = ["connection {}".format(i) for i in range(40)]
layout = GridLayout(cols=2, padding=10, spacing=10, size_hint_y=None)
layout.bind(minimum_height=layout.setter("height"))
for element in base:
layout.add_widget(Button(text=element, size=(50, 50), size_hint=(1, None),
background_color=(0.5, 0.5, 0.5, 1), color=(1, 1, 1, 1)))
right_btn = Button(text=">", id=element, size=(50,50), size_hint=(None, None), background_color=(0, 1, 0, 1), color=(1, 1, 1, 1))
right_btn.bind(on_press=partial(self.open_connected, right_btn))
layout.add_widget(right_btn)
scrollview = self.ids['view']
scrollview.add_widget(layout)
def open_connected(self, fun, name):
self.manager.get_screen('connection_screen').ids.title.text = name.id
self.manager.current = "connection_screen"
class Connection(Screen):
isShownMenu = BooleanProperty(True)
def __init__(self, **kwargs):
super(Connection, self).__init__(**kwargs)
class Py3Shell(Screen):
isShownMenu = BooleanProperty(True)
def __init__(self, **kwargs):
super(Py3Shell, self).__init__(**kwargs)
def on_enter(self, *args):
super().on_enter(*args)
self.ids.ti.focus = True
class GUI(App):
def build(self):
sm = ScreenManager()
sm.add_widget(Main())
sm.add_widget(Connection())
sm.add_widget(Py3Shell())
return sm
if __name__ == '__main__':
GUI().run()