我现在不知道如何描述问题。但是当你启动我的程序并按“检查词”时,你会看到标签超出了范围。当我添加的单词比过去的单词长时,我需要。我需要把这个词加长到右边。
我附上了一个我需要标签的例子。
from kivy.config import Config
Config.set("graphics", "resizable", 0)
Config.set("graphics", "width", 300)
Config.set("graphics", "height", 600)
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.screenmanager import Screen, ScreenManager, SlideTransition
from kivy.uix.gridlayout import GridLayout
from kivy.uix.widget import Widget
from kivy.lang import Builder
Builder.load_string('''
<EngAppMenu>:
background_normal: ''
background_color: (43/255, 61/255, 91/255, 1)
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
GridLayout:
cols: 1
pos_hint: {'top': 0.95, 'center_x': 0.5}
spacing: 10
size_hint: 0.72, 0.18
Button:
text: "Check words"
background_normal: ''
background_color: (26/255, 45/255, 64/255, 1)
#size_hint: 0.08, 0.67
#size: 200, 50
on_press: root.manager.current = 'checkwords'
Button:
text: "Add words"
background_normal: ''
background_color: (26/255, 45/255, 64/255, 1)
#size_hint: 0.67, 0.08
#size: 200, 50
on_press: root.manager.current = 'addwords'
<AddWordsMenu>:
background_normal: ''
background_color: (43/255, 61/255, 91/255, 1)
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
GridLayout:
cols: 1
pos_hint: {'top': 0.95, 'center_x': 0.5}
spacing: 8
size_hint: 0.8, 0.2
TextInput:
multiline: False
hint_text: "Original word"
id: eng_words
on_text_validate:
translation_words.focus=True
TextInput:
multiline: False
hint_text: "Translation word"
id: translation_words
GridLayout:
cols: 1
pos_hint: {'top': 0.73, 'center_x': 0.5}
spacing: 8
size_hint: 0.8, 0.08
Button:
text: "Save"
background_normal: ''
background_color: (26/255, 45/255, 64/255, 1)
on_press:
app.save(eng_words.text, translation_words.text)
eng_words.text = ""
translation_words.text = ""
GridLayout:
cols: 1
pos_hint: {'top': 0.1, 'center_x': 0.5}
spacing: 8
size_hint: 0.8, 0.07
Button:
text: "Menu"
background_normal: ''
background_color: (26/255, 45/255, 64/255, 1)
on_press:
root.manager.current = 'menu'
<CheckWordsMenu>:
background_normal: ''
background_color: (43/255, 61/255, 91/255, 1)
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
GridLayout:
cols: 1
pos_hint: {'top': 0.95, 'center_x': 0.5}
spacing: 8
size_hint: 0.8, 0.07
Button:
text: "Menu"
background_normal: ''
background_color: (26/255, 45/255, 64/255, 1)
on_press: root.manager.current = 'menu'
GridLayout:
cols: 1
pos_hint: {'top': 0.85, 'center_x': 0.41}
spacing: 5
size_hint: 0.8, 0.01
halign: 'left'
valign: 'center'
Label:
id: text1
text: "Hello"
height: self.texture_size[1]
size_hint: None, None
Label:
id: text2
text: "Hello22323213"
height: self.texture_size[1]
size_hint: None, None
Label:
id: text3
text: "Hello223213"
height: self.texture_size[1]
size_hint: None, None
Label:
id: text4
text: "Hi13"
height: self.texture_size[1]
size_hint: None, None
''')
class EngAppMenu(Screen, GridLayout):
pass
class AddWordsMenu(Screen, GridLayout):
pass
class CheckWordsMenu(Screen, GridLayout):
pass
sm = ScreenManager()
sm.add_widget(EngAppMenu(name='menu'))
sm.add_widget(AddWordsMenu(name="addwords"))
sm.add_widget(CheckWordsMenu(name="checkwords"))
class EngApp(App):
def build(self):
return sm
def save(self, engw, trnw):
eng = open('englishwords.txt','a', encoding='utf_8')
eng.write(engw + "\n")
eng.close()
trn = open('translationwords.txt','a', encoding='utf_8')
trn.write(trnw + "\n")
trn.close()
if __name__ == '__main__':
EngApp().run()
from kivy.config import Config
Config.set("graphics", "resizable", 0)
Config.set("graphics", "width", 300)
Config.set("graphics", "height", 600)
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.screenmanager import Screen, ScreenManager, SlideTransition
from kivy.uix.gridlayout import GridLayout
from kivy.uix.widget import Widget
from kivy.lang import Builder
Builder.load_string('''
<EngAppMenu>:
background_normal: ''
background_color: (43/255, 61/255, 91/255, 1)
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
GridLayout:
cols: 1
pos_hint: {'top': 0.95, 'center_x': 0.5}
spacing: 10
size_hint: 0.72, 0.18
Button:
text: "Check words"
background_normal: ''
background_color: (26/255, 45/255, 64/255, 1)
#size_hint: 0.08, 0.67
#size: 200, 50
on_press: root.manager.current = 'checkwords'
Button:
text: "Add words"
background_normal: ''
background_color: (26/255, 45/255, 64/255, 1)
#size_hint: 0.67, 0.08
#size: 200, 50
on_press: root.manager.current = 'addwords'
<AddWordsMenu>:
background_normal: ''
background_color: (43/255, 61/255, 91/255, 1)
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
GridLayout:
cols: 1
pos_hint: {'top': 0.95, 'center_x': 0.5}
spacing: 8
size_hint: 0.8, 0.2
TextInput:
multiline: False
hint_text: "Original word"
id: eng_words
on_text_validate:
translation_words.focus=True
TextInput:
multiline: False
hint_text: "Translation word"
id: translation_words
GridLayout:
cols: 1
pos_hint: {'top': 0.73, 'center_x': 0.5}
spacing: 8
size_hint: 0.8, 0.08
Button:
text: "Save"
background_normal: ''
background_color: (26/255, 45/255, 64/255, 1)
on_press:
app.save(eng_words.text, translation_words.text)
eng_words.text = ""
translation_words.text = ""
GridLayout:
cols: 1
pos_hint: {'top': 0.1, 'center_x': 0.5}
spacing: 8
size_hint: 0.8, 0.07
Button:
text: "Menu"
background_normal: ''
background_color: (26/255, 45/255, 64/255, 1)
on_press:
root.manager.current = 'menu'
<CheckWordsMenu>:
background_normal: ''
background_color: (43/255, 61/255, 91/255, 1)
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
GridLayout:
cols: 1
pos_hint: {'top': 0.95, 'center_x': 0.5}
spacing: 8
size_hint: 0.8, 0.07
Button:
text: "Menu"
background_normal: ''
background_color: (26/255, 45/255, 64/255, 1)
on_press: root.manager.current = 'menu'
GridLayout:
cols: 1
pos_hint: {'top': 0.85, 'center_x': 0.41}
spacing: 5
size_hint: 0.8, 0.01
halign: 'left'
valign: 'center'
Label:
id: text1
text: "Hello"
height: self.texture_size[1]
size_hint: None, None
Label:
id: text2
text: "Hello22323213"
height: self.texture_size[1]
size_hint: None, None
Label:
id: text3
text: "Hello223213"
height: self.texture_size[1]
size_hint: None, None
Label:
id: text4
text: "Hi13"
height: self.texture_size[1]
size_hint: None, None
''')
class EngAppMenu(Screen, GridLayout):
pass
class AddWordsMenu(Screen, GridLayout):
pass
class CheckWordsMenu(Screen, GridLayout):
pass
sm = ScreenManager()
sm.add_widget(EngAppMenu(name='menu'))
sm.add_widget(AddWordsMenu(name="addwords"))
sm.add_widget(CheckWordsMenu(name="checkwords"))
class EngApp(App):
def build(self):
return sm
def save(self, engw, trnw):
eng = open('englishwords.txt','a', encoding='utf_8')
eng.write(engw + "\n")
eng.close()
trn = open('translationwords.txt','a', encoding='utf_8')
trn.write(trnw + "\n")
trn.close()
if __name__ == '__main__':
EngApp().run()
我现在不知道如何描述问题。但是当你启动我的程序并按“检查词”时,你会看到标签超出了范围。当我添加的单词比过去的单词长时,我需要。我需要把这个词加长到右边。
我附上了一个我需要标签的例子。
from kivy.config import Config
Config.set("graphics", "resizable", 0)
Config.set("graphics", "width", 300)
Config.set("graphics", "height", 600)
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.screenmanager import Screen, ScreenManager, SlideTransition
from kivy.uix.gridlayout import GridLayout
from kivy.uix.widget import Widget
from kivy.lang import Builder
Builder.load_string('''
<EngAppMenu>:
background_normal: ''
background_color: (43/255, 61/255, 91/255, 1)
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
GridLayout:
cols: 1
pos_hint: {'top': 0.95, 'center_x': 0.5}
spacing: 10
size_hint: 0.72, 0.18
Button:
text: "Check words"
background_normal: ''
background_color: (26/255, 45/255, 64/255, 1)
#size_hint: 0.08, 0.67
#size: 200, 50
on_press: root.manager.current = 'checkwords'
Button:
text: "Add words"
background_normal: ''
background_color: (26/255, 45/255, 64/255, 1)
#size_hint: 0.67, 0.08
#size: 200, 50
on_press: root.manager.current = 'addwords'
<AddWordsMenu>:
background_normal: ''
background_color: (43/255, 61/255, 91/255, 1)
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
GridLayout:
cols: 1
pos_hint: {'top': 0.95, 'center_x': 0.5}
spacing: 8
size_hint: 0.8, 0.2
TextInput:
multiline: False
hint_text: "Original word"
id: eng_words
on_text_validate:
translation_words.focus=True
TextInput:
multiline: False
hint_text: "Translation word"
id: translation_words
GridLayout:
cols: 1
pos_hint: {'top': 0.73, 'center_x': 0.5}
spacing: 8
size_hint: 0.8, 0.08
Button:
text: "Save"
background_normal: ''
background_color: (26/255, 45/255, 64/255, 1)
on_press:
app.save(eng_words.text, translation_words.text)
eng_words.text = ""
translation_words.text = ""
GridLayout:
cols: 1
pos_hint: {'top': 0.1, 'center_x': 0.5}
spacing: 8
size_hint: 0.8, 0.07
Button:
text: "Menu"
background_normal: ''
background_color: (26/255, 45/255, 64/255, 1)
on_press:
root.manager.current = 'menu'
<CheckWordsMenu>:
background_normal: ''
background_color: (43/255, 61/255, 91/255, 1)
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
GridLayout:
cols: 1
pos_hint: {'top': 0.95, 'center_x': 0.5}
spacing: 8
size_hint: 0.8, 0.07
Button:
text: "Menu"
background_normal: ''
background_color: (26/255, 45/255, 64/255, 1)
on_press: root.manager.current = 'menu'
GridLayout:
cols: 1
pos_hint: {'top': 0.85, 'center_x': 0.41}
spacing: 5
size_hint: 0.8, 0.01
halign: 'left'
valign: 'center'
Label:
id: text1
text: "Hello"
height: self.texture_size[1]
size_hint: None, None
Label:
id: text2
text: "Hello22323213"
height: self.texture_size[1]
size_hint: None, None
Label:
id: text3
text: "Hello223213"
height: self.texture_size[1]
size_hint: None, None
Label:
id: text4
text: "Hi13"
height: self.texture_size[1]
size_hint: None, None
''')
class EngAppMenu(Screen, GridLayout):
pass
class AddWordsMenu(Screen, GridLayout):
pass
class CheckWordsMenu(Screen, GridLayout):
pass
sm = ScreenManager()
sm.add_widget(EngAppMenu(name='menu'))
sm.add_widget(AddWordsMenu(name="addwords"))
sm.add_widget(CheckWordsMenu(name="checkwords"))
class EngApp(App):
def build(self):
return sm
def save(self, engw, trnw):
eng = open('englishwords.txt','a', encoding='utf_8')
eng.write(engw + "\n")
eng.close()
trn = open('translationwords.txt','a', encoding='utf_8')
trn.write(trnw + "\n")
trn.close()
if __name__ == '__main__':
EngApp().run()