2017-12-11 3 views
1
ScrollView: 
    id: historyscroll 
    size_hint: 1, 0.925 
    pos_hint: {"x": 0, "top": 1} 
    Label: 
    id: historybox 
    text: "start" 
    size_hint: 1, None 
    size_hint_y: None 
    height: self.texture_size[1] 

Ausgabe: Text wird nicht angezeigt. Wenn Sie der Beschriftung einen neuen Text hinzufügen, wird das Wort pause mit unterschiedlichen Schriftgrößen angezeigt.Kivy-Label-Widget Ausgabe

Issue2:

TextInput: 
    text: "localhost:" 
    size_hint: 1, 0.06 
    pos_hint: {"x": 0, "y": 0} 
    id: cmdbox 
    multiline: False 
    text_validate_unfocus:False 
    font_size: "20sp" 

Nach etwas in das Textfeld eingeben, manchmal einige wierd Bild wird angezeigt. Auch text_validate_unfocus: False nicht Textfeld nicht daran hindert, unfocusing wenn Enter-Taste

bearbeiten gedrückt wird: Ganze Code: main.py:

#-*-coding:utf8;-*- 
#qpy:3 
#qpy:kivy 

from kivy.app import App 
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition 
from kivy.clock import Clock 
from kivy.core.window import Window 
from game import Game 

class Sm(ScreenManager): 
    pass 

class GameScreen(Screen): 
    def __init__(self, **kwargs): 
    super(GameScreen, self).__init__(**kwargs) 
    self.game = Game() 
    self.add_widget(self.game) 
    self.ids.cmdbox.bind(on_text_validate=self.cmdreturn) 
    self.ids.cmdbox.bind(focus=self.cmdfocus) 
    self.ids.historybox.text=" "*(Window.width*75/1048) 
    #Clock.schedule_interval(self.render, 0.5) 
    def cmdreturn(self, args): 
    self.cmd = self.ids.cmdbox.text 
    #self.ids.historybox.insert_text("\n"+self.cmd) 
    self.ids.historybox.text += "\n" + self.cmd 
    self.cmdexecute(self.cmd.split(str(self.game.current_)+":")[1]) 
    self.ids.cmdbox.text = str(self.game.current_) + ":" 
    def cmdexecute(self, cmd): 
    print(cmd) 
    if cmd == "fill": 
     self.ids.historybox.text+="\nfill"*30 
    if cmd == "clear": 
     self.ids.historybox.text= " "*(Window.width*75/1048) 
    if cmd == "ls": 
     self.ids.historybox.text= "\n"+str(self.game.current.folders.keys()) 
    def cmdfocus(self, instance, value): 
    if value: 
     self.ids.cmdbox.pos_hint={"x":0, "y":0.45} 
     self.ids.historyscroll.size_hint=(1, 0.475) 
    else: 
     self.ids.cmdbox.pos_hint={"x":0, "y":0} 
     self.ids.historyscroll.size_hint=(1, 0.925) 

class MenuScreen(Screen): 
    pass 

class PauseScreen(Screen): 
    pass 

class OptionsScreen(Screen): 
    pass 

class GameApp(App): 
    def build(self): 
    sm = Sm() 
    sm.add_widget(MenuScreen(name="menu")) 
    sm.add_widget(GameScreen(name="game")) 
    sm.add_widget(PauseScreen(name="pause")) 
    sm.add_widget(OptionsScreen(name="options")) 
    sm.transition = NoTransition() 
    return sm 

GameApp().run() 

game.kv:

#kivy 1.10.0 

<GameScreen>: 
    id:gscreen 
    FloatLayout: 
    Button: 
     text:"pause" 
     size_hint:(0.15, 0.05) 
     pos_hint:{"right":0.98, "top":0.98} 
     on_press:root.manager.current="pause" 
    ScrollView: 
     id: historyscroll 
     size_hint: 1, 0.925 
     pos_hint: {"x": 0, "top": 1} 
     Label: 
     id: historybox 
     #readonly: True 
     text: "start" 
     size_hint: 1, None 
     size_hint_y: None 
     height: self.texture_size[1] 
     #height: max(self.minimum_height, historyscroll.height) 
     #multiline: True 
     #foreground_color: (1,1,1,1) 
     #background_color: (255,255,255,0) 
     #font_size: "17sp" 
     #halign: "left" 
     #text_size:(self.width, "None") 
    TextInput: 
     text: "localhost:" 
     size_hint: 1, 0.06 
     pos_hint: {"x": 0, "y": 0} 
     id: cmdbox 
     multiline: False 
     text_validate_unfocus:False 
     font_size: "20sp" 

<MenuScreen>: 
    FloatLayout: 
    Button: 
     text:"start" 
     size_hint:(0.3, 0.1) 
     pos_hint:{"center_x":0.5, "center_y":0.61} 
     on_press:root.manager.current="game" 
    Button: 
     text:"options" 
     size_hint:(0.3, 0.1) 
     pos_hint:{"center_x":0.5, "center_y":0.5} 
     on_press:root.manager.current="options" 
    Button: 
     text:"exit" 
     size_hint:(0.3, 0.1) 
     pos_hint:{"center_x":0.5, "center_y":0.39} 
     on_press:quit 

<OptionsScreen>: 
    FloatLayout: 
    Button: 
     text:"back" 
     size_hint:(0.3, 0.1) 
     pos_hint:{"center_x":0.5, "center_y":0.5} 
     on_press:root.manager.current="menu" 


<PauseScreen>: 
    FloatLayout: 
    Button: 
     text:"back" 
     size_hint:(0.3, 0.1) 
     pos_hint:{"center_x":0.5, "center_y":0.495} 
     on_press:root.manager.current="game" 
    Button: 
     text:"exit" 
     size_hint:(0.3, 0.1) 
     pos_hint:{"center_x":0.5, "center_y":0.605} 
     on_press:root.manager.current="menu" 

Spiel .py:

from kivy.uix.widget import Widget 
from random import randint 

class Game(Widget): 
    def __init__(self, **kwargs): 
    super(Game, self).__init__(**kwargs) 
    self.localhost = "5255.7611" 
    self.internet = Internet(self.localhost) 
    self.current_ = "localhost" 
    self.current = self.internet.links[self.localhost.split(".")[0]].links[self.localhost.split(".")[1]] 

class Internet: 
    def __init__(self, localhost): 
    self.links = {} 
    self.links[str(localhost)[:4]] = Router(str(localhost)[:4], self) 
    self.links[str(localhost)[:4]].islocal(localhost) 
    def Crouter(self): 
    tmp = str(randint(1000, 9999)) 
    if not str(tmp) in self.links: 
     self.links[str(tmp)] = Router(tmp, self) 
    else: self.Crouter 

class Computer: 
    def __init__(self, ip, router): 
    self.ip = ip 
    self.router = router 
    self.islocal = False 
    self.folders = {"programs":Folder("programs",[], {}), 
        "downloads":Folder("downloads",[], {})} 

class Folder: 
    def __init__(self, name, content, data): 
    self.content = content 
    self.data = data 

class File: 
    def __init__(self, content, data): 
    self.content = content 
    self.data = data 

class Router: 
    def __init__(self, ip, internet): 
    self.ip = ip 
    self.internet = internet 
    self.links = {} 
    def Ccomputer(self): 
    tmp = str(randint(1000, 9999)) 
    if not str(tmp) in self.links: 
     self.links[str(tmp)] = Computer(str(tmp)+self.ip, self) 
    else: self.Ccomputer 
    def islocal(self, localhost): 
    self.links[str(localhost)[5:]] = Computer(str(localhost), self) 
    self.links[str(localhost)[5:]].islocal = True 

(Btw, ich benutze qpython- kivy) Issue in short: Die Texteingabe (id: cmdbox) beim Bearbeiten zeigt manchmal seltsame Bilder anstelle von Text an. Auch das Etikett (ID: historybox) zeigt nicht den richtigen Text (es zeigt nur "Pause" in verschiedenen Schriftgrößen jedes Mal)

Edit2: Endlich einige Bilder. https://www.dropbox.com/sh/i6t192ujys2hivz/AACPR5Sgb72Mv8M7gB3DiGmNa?dl=0

+0

bekommen Was ist die Frage? https://stackoverflow.com/help/mcve – EL3PHANTEN

+0

@ EL3PHANTEN Ich hoffe, ich habe mein Problem besser erklärt. Ich habe auch den ganzen Code (obwohl unnötig) für jeden, der mein Programm neu erstellen möchte – Madworks

Antwort

0

Für die erste Ausgabe im __init__ des Bildschirms Sie den Text Ihres Etiketts

Für die zweite ersetzen, weiß ich nicht, ob das Objekt in Kivy existiert Wenn Sie das behalten wollen konzentrieren sich in Ihrem TextInput Versuchen sie folgendes:

... 
class GameScreen(Screen): 
    def __init__(self, **kwargs): 
     super(GameScreen, self).__init__(**kwargs) 
     self.game = Game() 
     self.add_widget(self.game) 
     self.ids.cmdbox.bind(on_text_validate=self.cmdreturn) 
     self.ids.cmdbox.bind(focus=self.cmdfocus) 
     #self.ids.historybox.text=" "*(Window.width*75/1048) 
     #Clock.schedule_interval(self.render, 0.5) 

    def cmdreturn(self, args): 
     self.cmd = self.ids.cmdbox.text 
     #self.ids.historybox.insert_text("\n"+self.cmd) 
     self.ids.historybox.text += "\n" + self.cmd 
     self.cmdexecute(self.cmd.split(str(self.game.current_)+":")[1]) 
     self.ids.cmdbox.text = str(self.game.current_) + ":" 
     Clock.schedule_once(self.refocus) 

    def refocus(self, *args): 
     self.ids.cmdbox.focus = True 
... 

Und ich kann nichts über die seltsamen Bilder sagen, weil ich sie nicht

+0

Ich habe auskommentiert, was Sie gesagt haben und das Programm ausgeführt. Zuerst las das Widget "start", aber wenn ich den Text des Labels über die Texteingabe ändere, zeigt das Label "Pause" an. Btw würde mit qpython das Problem "seltsames Bild" verursachen? – Madworks

+0

Ich habe gerade das gleiche Programm mit pydroid 3 (ein anderer Python-Compiler für Android) versucht und es gab kein Problem! Yay. Aber wieso würde qpython solch einen Fehler anzeigen? Edit: Ich habe der Hauptfrage gerade Screenshots hinzugefügt. – Madworks

+0

ok jetzt sehe ich, im Allgemeinen diese Bilder sind aufgrund einer ungültigen Eigenschaft oder ein ungültiges Format der Farbe. Entfernen Sie die Unfocus-Eigenschaft und versuchen Sie es erneut auf qpython –