2017-05-25 402 views
0

我正在開發一個簡單的Notes應用程序。這就是我現在添加Note的屏幕的樣子。 ![enter image description herekivy TextInput更改字體顏色添加背景線

我想實現兩件事情

1.更改我的TextInput的字體顏色爲白色。

2.添加命令行來我的TextInput所看到的畫面

enter image description here

該行應始終即使將TextInput是空可見。從我的Python腳本

提取:(!謝謝)從我的KV文件

class NewNoteView(ModalView): 
    pass 

提取

<NewNoteView>: 
    BoxLayout: 
     orientation: 'vertical' 

     BoxLayout: 
      size_hint_y: 0.2 
      canvas.before: 
       Color: 
        rgb: 33/255, 41/255, 55/255 
       Rectangle: 
        pos: self.pos 
        size: self.size 
      orientation: 'vertical' 
      BoxLayout: 
       Button: 
        size_hint_x:0.1 
        text: 'x' 
        font_size: self.height*0.5 
        background_color: 0, 0, 0, 0 
        on_press: root.dismiss() 
       Label: 
        text: 'New Label' 

       Button: 
        size_hint_x:0.1 
        text:'+' 
        font_size: self.height*0.5 
        background_color: 0, 0, 0, 0 
        on_press: app.root.notifyP() 

       Button: 
        size_hint_x:0.1 
        text: 'L' 
        font_size: self.height*0.5 
        background_color: 0, 0, 0, 0 

      BoxLayout: 
       TextInput: 
        font_size: self.height*0.5 
        background_color: 0, 0, 0, 0 
        cursor_color: 1, 1, 1, 1 

        hint_text: 'Heading' 
        multiline: False 
        padding_x: [30,30] 

       Button: 
        size_hint_x: 0.2 
     BoxLayout: 
      canvas.before: 
       Color: 
        rgba: [38/255, 49/255, 70/255,1] 
       Rectangle: 
        pos: self.pos 
        size: self.size 
      TextInput: 
       background_color: 0, 0, 0, 0 
       cursor_color: 1, 1, 1, 1 
       color: 1, 1, 1, 1 
       hint_text: 'Body' 
       padding_x: [30,30] 

回答

0

你的問題非常清晰的結構,但你並沒有真正做你的研究正確,你是否?至少關於第一個問題。

  1. 答案很簡單:使用foreground_color屬性並將其設置爲1, 1, 1, 1;從文檔:

(fore_ground顏色是)當前顏色的前景的,在(R,G, B,A)的格式。默認爲黑色。

  1. 現在這一個是更有趣和複雜一點。直接的解決方案是在畫布中使用Line。像這樣將白線添加到窗口小部件在.kv文件底部:

canvas.before: Color: rgba: 1, 1, 1, 1 Line: points: self.x + 20, self.y, self.x + self.width - 20, self.y width: 1

而且它看起來像這樣,當我改變你的應用程序使用兩個TextInputs: How it looks

但據我所知,你只想在筆記中有一個TextInput。所以你必須找出線的高度並且每x個像素畫一條線。 Here's我發現了什麼。您需要使用minimum_height或line_height加line_spacing。另外,我不認爲你可以在.kv中做到這一點,我想你需要在Python中爲它寫一個方法。

我會推薦使用我的方法與額外的TextInputs。您可以綁定「輸入」以每次創建一個新的TextInput,以便可以擁有無​​限的線條。我相信這樣會更容易,但是你可以這樣做。