I am working in kivy (python) and I need dropdown to place here instead of textinput. but I could not do this, help me to continue work.the screenshot is following. my goal is to replace these textinputs with dropdowns.
enter image description here
The py file code is
import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.dropdown import DropDown
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.properties import ObjectProperty
from kivy.lang import Builder
class CustomDropDown(DropDown):
pass
class delivery_managementWindow(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.dropdown = CustomDropDown()
self.mainbutton = Button(text ='Do you in college?',
size_hint_x = 0.6, size_hint_y = 0.15)
self.add_widget(self.mainbutton)
self.mainbutton.bind(on_release = self.dropdown.open)
self.dropdown.bind(on_select = lambda\
instance, x: setattr(self.mainbutton, 'text', x))
self.dropdown.bind(on_select = self.callback)
def callback(self, instance, x):
print ( "The chosen mode is: {0}" . format ( x ) )
class delivery_managementApp(App):
def build(self):
return delivery_managementWindow()
if __name__ =='__main__':
delivery_managementApp().run()
Now its kv file is also
<CustomDropDown>:
Button:
text: 'College Name'
size_hint_y: None
height: 44
on_release: root.select('College is')
Label:
text: 'Not in college'
size_hint_y: None
height: 44
Button:
text: 'KccItm'
size_hint_y: None
height: 44
on_release: root.select('Kcc')
<delivery_managementWindow>:
id:delivery_managment_main_window
orientation:'vertical'
padding:5
spacing:5
canvas.before:
Color:
rgba:(.1,.30,.35,1)
Rectangle:
pos:self.pos
size:self.size
BoxLayout:
id:header
size_hint_x:1
size_hint_y:None
height:50
canvas.before:
Color:
rgba:(.06,.45,.45,1)
Rectangle:
pos:self.pos
size:self.size
Label:
text:"Delivery Management"
bold: True
font_size:18
# color:(.06,.45,.45,1)
BoxLayout:
id:''
orientation:'horizontal'
BoxLayout:
id:add_edit_form
orientation:'vertical'
size_hint_y:1
size_hint_x:1.5
spacing:5
padding:5
# height:40
canvas.before:
Color:
# rgba:(.02,.25,.45,1)
Rectangle:
pos:self.pos
size:self.size
BoxLayout:
size_hint_y:None
size_hint_x:1
# padding:5
height:40
canvas.before:
Color:
rgba:(1,1,1,.8)
Rectangle:
pos:self.pos
size:self.size
Label:
id:lbl_header
text:"Add New/Edit Delivery"
font_size:17
bold: True
color:(0,0,1,1)
GridLayout:
id:grd
cols:2
size_hint_y:1
size_hint_x:1
canvas.before:
Color:
rgba:(.06,.45,.45,1)
Rectangle:
pos:self.pos
size:self.size
Label:
text:"Delivery :"
bold: True
font_size:17
BoxLayout:
id:dropdown_box
Label:
text:"Our Ref: Inv-sup :"
bold: True
font_size:17
TextInput:
Label:
text:"Invoice :"
bold: True
font_size:17
TextInput:
Label:
text:"Supplier :"
bold: True
font_size:17
TextInput:
Label:
text:"Date :"
bold: True
font_size:17
TextInput:
BoxLayout:
cols:2
CheckBox:
Label:
text:'Delivery for Store Room'
Button:
id:btn_proceed
text:'Proceed Next'
BoxLayout:
id:keyboard
size_hint_y:1
size_hint_x:1
canvas.before:
Color:
rgba:(0,0,1,1)
Rectangle:
pos:self.pos
size:self.size
BoxLayout:
id:keypad_section
orientation:'vertical'
size_hint_y:1
size_hint_x:.7
# padding:5
canvas.before:
Color:
rgba:(.1,.30,.35,1)
Rectangle:
pos:self.pos
size:self.size
AnchorLayout:
size_hint_x:1
size_hint_y:.2
anchor_x: 'center'
anchor_y: 'center'
canvas:
Color:
rgba:(1,1,1,.9)
Rectangle:
pos: self.pos
size: self.size
Button:
text: 'Go To Sale'
size_hint_y:.7
size_hint_x:.5
font_size:17
bold: True
background_normal:''
background_color:(.06,.45,.45,1)
GridLayout:
cols:3
id:keypad
size_hint_y:1
size_hint_x:1
spacing:5
padding:5
canvas.before:
Color:
rgba:(.1,.30,.35,1)
Rectangle:
pos:self.pos
size:self.size
Button:
text:'1'
bold: True
font_size:18
background_normal:''
background_color:(.06,.45,.45,1)
Button:
text:'2'
bold: True
font_size:18
background_normal:''
background_color:(.06,.45,.45,1)
Button:
text:'3'
bold: True
font_size:18
background_normal:''
background_color:(.06,.45,.45,1)
Button:
text:'4'
bold: True
font_size:18
background_normal:''
background_color:(.06,.45,.45,1)
Button:
text:'5'
bold: True
font_size:18
background_normal:''
background_color:(.06,.45,.45,1)
Button:
text:'6'
bold: True
font_size:18
background_normal:''
background_color:(.06,.45,.45,1)
Button:
text:'7'
bold: True
font_size:18
background_normal:''
background_color:(.06,.45,.45,1)
Button:
text:'8'
bold: True
font_size:18
background_normal:''
background_color:(.06,.45,.45,1)
Button:
text:'9'
bold: True
font_size:18
background_normal:''
background_color:(.06,.45,.45,1)
Button:
text:'00'
bold: True
font_size:18
background_normal:''
background_color:(.06,.45,.45,1)
Button:
text:'0'
bold: True
font_size:18
background_normal:''
background_color:(.06,.45,.45,1)
Button:
text:'*'
bold: True
font_size:18
background_normal:''
background_color:(.06,.45,.45,1)
Button:
text:'<--'
bold: True
font_size:18
background_normal:''
background_color:(.06,.45,.45,1)
Button:
text:'-'
bold: True
font_size:18
background_normal:''
background_color:(.06,.45,.45,1)
Button:
text:'Enter'
bold: True
font_size:18
background_normal:''
background_color:(.06,.45,.45,1)
BoxLayout:
id:btn_section
size_hint_y:.2
size_hint_x:1
spacing:5
padding:5
canvas.before:
Color:
rgba:(.1,.30,.35,1)
Rectangle:
pos:self.pos
size:self.size
Button:
id:btn_exit
text:'Exit'
size_hint_x:1
size_hint_y:1
font_size:18
bold:True
color:(.8,0,0,.8)
background_normal:''
background_color:(.06,.45,.45,1)
size_hint_x:1
size_hint_y:1
Button:
id:btn_finish
text: "Finish Delivery"
font_size:18
bold:True
background_normal:''
background_color:(.06,.45,.45,1)
size_hint_x:1
size_hint_y:1
You can create a DropDown to replace each TextInput. I will provide an example of how to do that for the delivery option and you can follow that pattern for any other DropDowns that you want.
First, define the main button for the new DropDown in the kv:
Label:
text:"Delivery :"
bold: True
font_size:17
# BoxLayout:
# id:dropdown_box
Button:
id: del_opt_main_butt
text: 'Select delivery option'
on_release: root.open_delivery_options_dropdown()
Then make a rule for the new DropDown (also in the kv):
<DeliveryOptionDropDown>:
on_select:
app.root.ids.del_opt_main_butt.text = args[1]
app.delivery_option_callback(*args)
Button:
text: 'Overnight'
size_hint_y: None
height: 44
on_release: root.select(self.text)
Button:
text: 'Two Day'
size_hint_y: None
height: 44
on_release: root.select(self.text)
Button:
text: 'Snail Mail'
size_hint_y: None
height: 44
on_release: root.select(self.text)
and define the new DropDown class:
class DeliveryOptionDropDown(DropDown):
pass
Then add the method to open the new Dropdown to the delivery_managementWindow class:
def open_delivery_options_dropdown(self):
self.delivery_options_dropdown = DeliveryOptionDropDown()
self.delivery_options_dropdown.open(self.ids.del_opt_main_butt)
Then add a callback to the App class:
def delivery_option_callback(self, instance, selection):
print('chosen delivery option is', selection)
Those last two methods are located in the delivery_managementWindow and the App classes just for simplicity (root and app are predefined variables in the kv).
Related
I created this widget in a .kv file that inherits from MDCard:
<ElementCard#MDCard>:
radius: '10dp'
spacing: '10dp'
padding: '10dp'
image: ''
text: ''
sub_text: ''
orientation: 'vertical'
md_bg_color: 0.87, 0, 0.49
ripple_behavior: True # effect
on_release:
app.root.transition = RiseInTransition()
Image:
source: root.image
halign: 'center'
MDBoxLayout:
orientation: 'vertical'
md_bg_color: 'green'
MDLabel:
text: root.text
color: 'white'
halign: 'center'
MDLabel:
text: root.sub_text
halign: 'center'
and I use it:
<ui>:
...
ElementCard:
text: 'IA'
sub_text: 'Inteligencia artificial'
image: 'images/image1.jpg'
on_release:
root.current = 'screen1'
...
The problem is that the ElementCard widget doesn't show the content:
ElementCard is the purple block and it covers all its content.
When I set the transparency in 0.5 the program looks like this:
50% transparency
The versions are these:
Kivy==2.1.0
kivymd==1.1.1
I've tried rebooting the machine, restarting the virtual environment, reinstalling kivy and kivymd but nothing works.
I think the problem is the inheritance because when I use directly the MDCard like in this code:
MDCard:
radius: '10dp'
spacing: '10dp'
padding: '10dp'
orientation: 'vertical'
md_bg_color: 0.87, 0, 0.49,0.6
ripple_behavior: True # effect
on_release:
app.root.transition = RiseInTransition()
Image:
source: 'images/image1.jpg'
halign: 'center'
MDBoxLayout:
orientation: 'vertical'
md_bg_color: 'green'
MDLabel:
text: 'IA'.
color: 'white'
halign: 'center'
MDLabel:
text: 'Inteligencia artificial'
halign: 'center'
With the last code the program works fine:
MDCard works normally.
main.py full code:
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager
from kivymd.app import MDApp
class Ui(ScreenManager):
pass
class MainApp(MDApp):
def build(self):
self.theme_cls.theme_style ='Dark'
self.theme_cls.primary_palette ='Teal'
Builder.load_file("design.kv")
return Ui()
def change_style(self, checked, value):
if value:
self.theme_cls.theme_style ='Dark'
pass
else:
self.theme_cls.theme_style ='Light'
pass
if __name__ == "__main__":
MainApp().run()
design.kv full code:
#:kivy 2.1.0
#:import RiseInTransition kivy.uix.screenmanager.RiseInTransition
#:import SlideTransition kivy.uix.screenmanager.SlideTransition
<CustomizeScreen#MDBoxLayout>:
orientation: 'vertical'
text: ''
padding: 100
MDLabel:
text: root.text
halign: 'center'
pos_hint:{'center_x': 0.5}
MDFillRoundFlatButton:
text: 'REGRESAR'
pos_hint: {'center_x': 0.5}
on_release:
app.root.current = 'screen_principal'
app.root.transition = SlideTransition(direction = 'left')
<ElementCard#MDCard>:
radius: '10dp'
spacing: '10dp'
padding: '10dp'
image: ''
text: ''
sub_text: ''
orientation: 'vertical'
md_bg_color: 0.87, 0, 0.49
ripple_behavior: True # effect
on_release:
app.root.transition = RiseInTransition()
Image:
source: root.image
halign: 'center'
MDBoxLayout:
orientation: 'vertical'
md_bg_color: 'green'
MDLabel:
text: root.text
color: 'white'
halign: 'center'
MDLabel:
text: root.sub_text
halign: 'center'
<ui>:
MDScreen:
name: 'screen_principal'
md_bg_color: "black"
MDBoxLayout:
orientation: "vertical"
MDBoxLayout:
size_hint: 1, 0.2 # x=1 ocupa todo, y=0.2 ocupa 20%
orientation: "horizontal"
padding: '10dp'
MDCard:
radius: '10dp'
padding: '10dp'
line_color: 1,0,1,1
MDLabel:
text: 'APLICACIÓN DE TECNOLOGÍA'
halign: 'center'
pos_hint: {'center_y': 0.5}
MDSwitch:
pos_hint: {'center_y': 0.5}
on_active:
app.change_style(*args)
MDGridLayout:
cols: 3
size_hint: 0.8, 0.8 # x=1 ocupa todo, y=0.8 ocupa 80%
pos_hint: {'center_x': 0.5}
padding: ['10dp','10dp','10dp','10dp']
spacing: '10dp'
ElementCard:
text: 'IA'
sub_text: 'Inteligencia artificial'
image: 'images/image1.jpg'
on_release:
root.current = 'screen1'
I commented this problem in the github kivyMD project, they marked as a bug and give me a couple of options to implement, link to github
Edit:
Thanks for pointing out my mistake with my link.
This is the first option:
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.card import MDCard
KV = """
<ElementCard>
MDLabel:
text: "HELLO WORLD"
MDScreen:
ElementCard:
size_hint: 0.5, 0.8
pos_hint: {"center_x": .5, "center_y": .5}
md_bg_color: 0.87, 0, 0.49, 1
"""
class ElementCard(MDCard):
pass
class MainApp(MDApp):
def build(self):
return Builder.load_string(KV)
MainApp().run()
and the 2nd:
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.card import MDCard
KV = """
<ElementCard#MDCard>
MDLabel:
text: "HELLO WORLD"
MDScreen:
ElementCard:
size_hint: 0.5, 0.8
pos_hint: {"center_x": .5, "center_y": .5}
md_bg_color: 0.87, 0, 0.49, 1
"""
class MainApp(MDApp):
def build(self):
return Builder.load_string(KV)
MainApp().run()
I guess that the kivymd developers will repair this bug in the future.
When I double click on the video, it goes full screen, but if I double click on it again, it doesn't go back to normal. However, the rest of the window elements are partially visible. The part of my .kv code responsible for the VideoPlayer is given below:
<VideosWindow>:
name: 'vids'
FloatLayout:
FileChooserListView:
id:chooser
path: root.get_files_list()
canvas.before:
Color:
rgb: .4, .5, .5
Rectangle:
pos: self.pos
size: self.size
on_selection: root.select(chooser.selection)
size_hint: (.9, .15)
pos_hint: {'x':.05, 'y':.8}
VideoPlayer:
id:vid
options: {'eos':'loop'}
size_hint: (.9, .7)
pos_hint: {'x':.05, 'y':.05}
Button:
size_hint_y: 0.3
height: 48
text: "open"
disabled: not chooser.selection
on_release: root.select(chooser.selection)
size_hint: (.45, .05)
pos_hint: {'x':.05, 'y':.00}
Button:
text: 'Go Back'
color: (1,1,1,1)
background_normal:''
background_color: (0.3,0.6,0.7,1)
on_release:
vid.state = 'pause'
app.root.current = 'saved_files'
size_hint: (.45, .05)
pos_hint: {'x':.50, 'y':.00}
VideosWindow class code:
class VideosWindow(Screen):
def get_files_list(self):
files = os.sep.join([my_folder,'mp4'])
return files
def select(self, filename):
self.ids.vid.source = filename[0]
self.ids.vid.state = 'play'
The screenshots of my program before and after I go fullscreen mode:
before
after
Solved this issue by adding VideoPlayer widget to the GridLayout. Now .kv code looks like this:
<VideosWindow>:
name: 'vids'
FloatLayout:
FileChooserListView:
id:chooser
path: root.get_files_list()
canvas.before:
Color:
rgb: .4, .5, .5
Rectangle:
pos: self.pos
size: self.size
on_selection: root.select(chooser.selection)
size_hint: (.9, .15)
pos_hint: {'x':.05, 'y':.8}
GridLayout:
cols:1
size_hint: (.9, .7)
pos_hint: {'x':.05, 'y':.05}
VideoPlayer:
id:vid
options: {'eos':'loop'}
Button:
size_hint_y: 0.3
height: 48
text: "open"
disabled: not chooser.selection
on_release: root.select(chooser.selection)
size_hint: (.45, .05)
pos_hint: {'x':.05, 'y':.00}
Button:
text: 'Go Back'
color: (1,1,1,1)
background_normal:''
background_color: (0.3,0.6,0.7,1)
on_release:
vid.state = 'pause'
app.root.current = 'saved_files'
size_hint: (.45, .05)
pos_hint: {'x':.50, 'y':.00}
Don't know if it is good decision but it works.
On display screen of my code i have used accordions, I have done every thing as instructed and the code for TextInput in that page is right but accordions are not working as intended and the textInput is not taking any inputs. I am new to kivy and as far as I know every thing seems right to me.
Heres my code:
import kivy
kivy.require('1.10.0')
from kivy.uix.stacklayout import StackLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.app import App
from kivy.uix.popup import Popup
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
from kivy.properties import ObjectProperty
from kivy.uix.textinput import TextInput
from kivy.properties import StringProperty
import json
Builder.load_file('VocabularyJournal.kv')
class MenuPage(Screen):
pass
class DisplayPage(Screen): # here is the display page[![enter image description here][1]][1]
search_box= ObjectProperty()
label_maening=StringProperty()
label_synonym=StringProperty()
label_ant=StringProperty()
label_sentence=StringProperty()
def search_function(self):
with open('vocab_words.json') as rfile:
data=json.load(rfile)
word=self.search_box.text
for value in data:
if value['word']==word:
self.label_maening=value['meaning']
self.label_synonym=value['synonym']
self.label_ant=value['antonyms']
self.label_sentence=value['sentence']
class WordInsertPage(Screen):
pass
class NewWordPage(Screen):
word_box = ObjectProperty()
meaning_box = ObjectProperty()
synonym_box = ObjectProperty()
ant_box = ObjectProperty()
sentence_box = ObjectProperty()
def saving_data(self):
with open('vocab_words.json') as rfile:
data=json.load(rfile)
entry={'word': self.word_box.text, 'meaning': self.meaning_box.text, 'synonym': self.synonym_box.text, 'antonyms': self.ant_box.text, 'sentence': self.sentence_box.text}
data.append(entry)
with open('vocab_words.json','w') as wfile:
json.dump(data,wfile,indent=4)
class FlashCard(Screen):
pass
class WordGroups(Screen):
pass
class Manager(ScreenManager):
pass
class VocabularyJournalApp(App):
def build(self):
return Manager()
object = VocabularyJournalApp()
object.run()
heres the kivy code-
<Manager>:
MenuPage:
name: 'menu'
WordInsertPage:
name: 'insertword'
NewWordPage:
name: 'newword'
FlashCard:
name: 'flashcard'
WordGroups:
name: 'wordgroup'
DisplayPage:
name: 'display'
<MenuPage>:
Label:
text: "Vocabulary Journal"
size_hint: .90,.10
StackLayout:
orientation: 'tb-rl'
spacing: 10
padding: 10
Button:
text: 'Search'
size_hint: None,.20
width: 130
background_down:'darkgrey.png'
on_press: root.manager.current='insertword'
Button:
text: 'New Word'
size_hint: None,.20
width: 130
background_down:'darkgrey.png'
on_press: root.manager.current='insertword'
Button:
text: 'Flash Cards'
size_hint: None,.20
width: 130
background_down:'darkgrey.png'
on_press: root.manager.current='flashcard'
Button:
text: 'Word Groups'
size_hint: None,.20
width: 130
background_down:'darkgrey.png'
on_press: root.manager.current='wordgroup'
<WordInsertPage>:
FloatLayout:
Button:
text: "New Word"
on_press: root.manager.current='newword'
font_size: 30
color: 0,0,0,1
size_hint: .2, .1
pos_hint: {"center_x": .5, "center_y": 0.3}
background_down: 'darkgrey.png'
Button:
text: "search word"
on_press: root.manager.current='display'
font_size: 30
color: 0,0,0,1
size_hint: .2, .1
pos_hint: {"center_x": .5, "center_y": 0.5}
background_down: 'darkgrey.png'
Button:
text: 'Flash Cards'
on_press: root.manager.current="flashcard"
font_size: 30
color: 0,0,0,1
size_hint: .2, .1
pos_hint: {"center_x": .5, "center_y": 0.7}
background_down: 'darkgrey.png'
<NewWordPage>:
id: refer_to_it
word_box: word_input
meaning_box: meaning_input
synonym_box: Synonym_input
ant_box: ant_input
sentence_box: sentence_input
StackLayout:
orientation: 'tb-rl'
spacing: 10
padding: 90
TextInput:
text: "write your word here"
color: 1,1,1,1
id: word_input
width: 300
size_hint: None, .10
TextInput:
text: "write meaning of your word here"
color: 1,1,1,1
id: meaning_input
width: 600
size_hint: None, .20
TextInput:
text: "write Synonyms of your word here"
color: 1,1,1,1
id: Synonym_input
width: 600
size_hint: None, .20
TextInput:
text: "write antonyms of your text here"
color: 1,1,1,1
id: ant_input
width: 600
size_hint: None, .20
TextInput:
text: "write a sentence based on your word here"
color: 1,1,1,1
id: sentence_input
width: 600
size_hint: None, .20
Button:
text: 'Save'
size_hint: None,.10
width: 130
background_down:'darkgrey.png'
on_press: refer_to_it.saving_data()
<DisplayPage>: # here is the display page
search_box: search_text
BoxLayout:
size_hint_y: None
height: '48dp'
TextInput:
text:'enter the word you wanna search here'
id: search_text
on_text_validate: root.search_function()
Accordion:
orientation: 'vertical'
AccordionItem:
title:'meaning'
Label:
text: root.label_maening
text_size: self.width, None
AccordionItem:
title:'Synonym'
Label:
text: root.label_synonym
text_size: self.width, None
AccordionItem:
title:'Antonym'
Label:
text: root.label_ant
text_size: self.width, None
AccordionItem:
title:'Sentence'
Label:
text: root.label_sentence
text_size: self.width, None
In principle I see three problems:
on_text_validate isn't fired in multiline inputs. You should set multiline property to False.
Use hint_text property to set the suggestion text.
The weird behavior of your accordion is probably caused because you are loading your kv file twice (Your "Multiple screens named ..." warnings are indicative of that.). I recommend renaming your kv to vocabularyjournal.kv and not using Builder.load_file (). You can look at this related answer.
main.py:
import kivy
kivy.require('1.10.0')
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty
from kivy.properties import StringProperty
import json
class MenuPage(Screen):
pass
class DisplayPage(Screen):
search_box= ObjectProperty()
label_maening=StringProperty()
label_synonym=StringProperty()
label_ant=StringProperty()
label_sentence=StringProperty()
def search_function(self):
with open('vocab_words.json') as rfile:
data=json.load(rfile)
word=self.search_box.text
for value in data:
if value['word']==word:
self.label_maening=value['meaning']
self.label_synonym=value['synonym']
self.label_ant=value['antonyms']
self.label_sentence=value['sentence']
class WordInsertPage(Screen):
pass
class NewWordPage(Screen):
word_box = ObjectProperty()
meaning_box = ObjectProperty()
synonym_box = ObjectProperty()
ant_box = ObjectProperty()
sentence_box = ObjectProperty()
def saving_data(self):
with open('vocab_words.json') as rfile:
data=json.load(rfile)
entry={'word': self.word_box.text, 'meaning': self.meaning_box.text, 'synonym': self.synonym_box.text, 'antonyms': self.ant_box.text, 'sentence': self.sentence_box.text}
data.append(entry)
with open('vocab_words.json','w') as wfile:
json.dump(data,wfile,indent=4)
class FlashCard(Screen):
pass
class WordGroups(Screen):
pass
class Manager(ScreenManager):
pass
class VocabularyJournalApp(App):
def build(self):
return Manager()
obj = VocabularyJournalApp()
obj.run()
vocabularyjournal.kv:
<Manager>:
MenuPage:
name: 'menu'
WordInsertPage:
name: 'insertword'
NewWordPage:
name: 'newword'
FlashCard:
name: 'flashcard'
WordGroups:
name: 'wordgroup'
DisplayPage:
name: 'display'
<MenuPage>:
Label:
text: "Vocabulary Journal"
size_hint: .90,.10
StackLayout:
orientation: 'tb-rl'
spacing: 10
padding: 10
Button:
text: 'Search'
size_hint: None,.20
width: 130
background_down:'darkgrey.png'
on_press: root.manager.current='insertword'
Button:
text: 'New Word'
size_hint: None,.20
width: 130
background_down:'darkgrey.png'
on_press: root.manager.current='insertword'
Button:
text: 'Flash Cards'
size_hint: None,.20
width: 130
background_down:'darkgrey.png'
on_press: root.manager.current='flashcard'
Button:
text: 'Word Groups'
size_hint: None,.20
width: 130
background_down:'darkgrey.png'
on_press: root.manager.current='wordgroup'
<WordInsertPage>:
FloatLayout:
Button:
text: "New Word"
on_press: root.manager.current='newword'
font_size: 30
color: 0,0,0,1
size_hint: .2, .1
pos_hint: {"center_x": .5, "center_y": 0.3}
background_down: 'darkgrey.png'
Button:
text: "search word"
on_press: root.manager.current='display'
font_size: 30
color: 0,0,0,1
size_hint: .2, .1
pos_hint: {"center_x": .5, "center_y": 0.5}
background_down: 'darkgrey.png'
Button:
text: 'Flash Cards'
on_press: root.manager.current="flashcard"
font_size: 30
color: 0,0,0,1
size_hint: .2, .1
pos_hint: {"center_x": .5, "center_y": 0.7}
background_down: 'darkgrey.png'
<NewWordPage>:
id: refer_to_it
word_box: word_input
meaning_box: meaning_input
synonym_box: Synonym_input
ant_box: ant_input
sentence_box: sentence_input
StackLayout:
orientation: 'tb-rl'
spacing: 10
padding: 90
TextInput:
hint_text: "write your word here"
color: 1,1,1,1
id: word_input
width: 300
size_hint: None, .10
TextInput:
hint_text: "write meaning of your word here"
color: 1,1,1,1
id: meaning_input
width: 600
size_hint: None, .20
TextInput:
hint_text: "write Synonyms of your word here"
color: 1,1,1,1
id: Synonym_input
width: 600
size_hint: None, .20
TextInput:
hint_text: "write antonyms of your text here"
color: 1,1,1,1
id: ant_input
width: 600
size_hint: None, .20
TextInput:
hint_text: "write a sentence based on your word here"
color: 1,1,1,1
id: sentence_input
width: 600
size_hint: None, .20
Button:
hint_text: 'Save'
size_hint: None,.10
width: 130
background_down:'darkgrey.png'
on_press: refer_to_it.saving_data()
<DisplayPage>: # here is the display page
search_box: search_text
BoxLayout:
size_hint_y: None
height: '48dp'
TextInput:
hint_text:'enter the word you wanna search here'
id: search_text
multiline: False
on_text_validate: root.search_function()
Accordion:
orientation: 'vertical'
AccordionItem:
title:'meaning'
Label:
text: root.label_maening
text_size: self.width, None
AccordionItem:
title:'Synonym'
Label:
text: root.label_synonym
text_size: self.width, None
AccordionItem:
title:'Antonym'
Label:
text: root.label_ant
text_size: self.width, None
AccordionItem:
title:'Sentence'
Label:
text: root.label_sentence
text_size: self.width, None
Note: You shouldn't use object as variable name. It is a built-in function.
I am trying to use kivy scrollview inside of EmployeeScreen class. it will not scroll!? what am I doing wrong? I hope this is not a duplicate, please help.
I went to this link Kivy ScrollView - Not Scrolling. which seems to be the only question relating to kivy scrollview not scrolling. this didn't solve my problem.
.py file:
`from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty
from kivy.uix.scrollview import ScrollView
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.stacklayout import StackLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
class LogInScreen(Screen):
pass
class EmployeeScreen(Screen):
pass
class Manager(ScreenManager):
login_screen = ObjectProperty(None)
employee_screen = ObjectProperty(None)
class CptApp(App):
icon = 'Images\login\cptlogo.png'
title = 'CPT'
def build(self):
return Manager()
if __name__=='__main__':
CptApp().run()`
.kv file:
<Manager>:
id: screen_manager
login_screen: login_screen
employee_screen: employee_screen
LogInScreen:
id: login_screen
name: 'login'
manager: screen_manager
FloatLayout:
StackLayout:
orientation: 'lr-tb'
canvas:
Color:
rgba: 1,1,1,1
Rectangle:
pos: self.pos
size: self.size
Image:
size_hint_y: .1
source: 'Images\login\cptbanner.jpg'
allow_stretch: True
keep_ratio: True
Image:
source: 'Images\login\HD7Brw.jpg'
allow_stretch: True
keep_ratio: False
Label:
size_hint_y: .05
size_hint_x: .5
pos_hint: {"x": .25, "y": .7}
markup: True
text: '[i][b][color=#000000]USER NAME[/color][/b][/i]'
TextInput:
id: 'username_input'
multiline: False
size_hint_x: .4
size_hint_y: .05
pos_hint: {"x": .3, "y": .65}
Label:
size_hint_y: .05
size_hint_x: .5
markup: True
text: '[i][b][color=#000000]PASSWORD[/color][/b][/i]'
pos_hint: {'x': .25, 'y': .5}
TextInput:
id: 'password_input'
multiline: False
password: True
size_hint_x: .4
size_hint_y: .05
pos_hint: {'x': .3, 'y': .45}
Image:
source: 'Images/login/loginbutton.png'
size_hint_x: .25
size_hint_y: .1
pos_hint: {'x': .375, 'y': .25}
Button:
id: 'login_button'
background_color: 0,0,0,0
markup: True
text: '[i][b][color=#000000]LOGIN[/color][/b][/i]'
size_hint_x: .25
size_hint_y: .1
pos_hint: {'x': .375, 'y': .25}
on_release: screen_manager.current = 'employeescreen'
EmployeeScreen:
id: employee_screen
name: 'employeescreen'
manager: screen_manager
StackLayout:
orientation: 'lr-tb'
canvas:
Color:
rgba: 1,1,1,1
Rectangle:
pos: self.pos
size: self.size
Image:
size_hint_y: .1
source: 'Images\login\cptbanner.jpg'
allow_stretch: True
keep_ratio: True
ScrollView:
do_scroll_x: False
size: root.size
pos: root.pos
GridLayout:
cols: 2
size_hint_y: None
height: self.minimum_height
pos: root.pos
Button:
height: 40
size_hint_y: None
text: 'TEST'
Button:
size_hint_x: 1
size_hint_y: None
text: 'TEST'
Button:
size_hint_x: 1
size_hint_y: None
text: 'TEST'
Button:
size_hint_x: 1
size_hint_y: None
text: 'TEST'
Button:
size_hint_x: 1
size_hint_y: None
text: 'TEST'
Button:
size_hint_x: 1
size_hint_y: None
text: 'TEST'
Button:
size_hint_x: 1
size_hint_y: None
text: 'TEST'
Button:
size_hint_x: 1
size_hint_y: None
text: 'TEST'
Button:
size_hint_x: 1
size_hint_y: None
text: 'TEST'
Button:
size_hint_x: 1
size_hint_y: None
text: 'TEST'
Button:
size_hint_x: 1
size_hint_y: None
text: 'TEST'
Button:
size_hint_x: 1
size_hint_y: None
text: 'TEST'
I was trying to use GridLayout in my .kv file, wrong, I had to create a class and override its init.
class MyLayout(GridLayout):
def __init__(self,**kwargs):
super(MyLayout,self).__init__(**kwargs)
self.size_hint_y = (None)
self.bind(minimum_height = self.setter('height'))
then I placed the class in the .kv file where GridLayout was.
I am trying to create a checkbox in my float layout area. I am getting the checkbox to generate but every time I click it goes from True to False even if it not on the box. Could someone provide some insight?
My code:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.checkbox import CheckBox
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
from kivy.uix.textinput import TextInput
from kivy.uix.widget import Widget
#######``Windows``#######
class MainScreen(Screen):
pass
class AnotherScreen(Screen):
def add(self, *args):
a = self.ids["a"].text
a = int(a)
self.ids["adds"]
plus = 1 + a
print plus
class ScreenManagement(ScreenManager):
pass
presentation = Builder.load_file("GUI_Style.kv")
class MainApp(App):
def build(self):
return presentation
if __name__ == "__main__":
MainApp().run()
My KV File:
#: import NoTransition kivy.uix.screenmanager.NoTransition
ScreenManagement:
transition: NoTransition()
MainScreen:
AnotherScreen:
<MainScreen>:
background_color: 0.5, 1, 0.22, 1
name: "main"
FloatLayout:
Button:
text: "Quit"
font_size: 50
color: 0,1,0,1
font_size: 25
size_hint: 0.3,0.2
pos_hint: {"x":0, "y":0}
on_release: app.window().stop()
Button:
on_release: app.root.current = "other"
text: "Next Screen"
font_size: 50
color: 0,1,0,1
font_size: 25
size_hint: 0.3,0.2
pos_hint: {"right":1, "top":1}
<AnotherScreen>:
name: "other"
canvas.before:
Color:
rgba: 1, 1, 1, 1
Rectangle:
pos: self.pos
size: self.size
FloatLayout:
CheckBox:
pos_hint: {"x":0.2, "y":0.2}
on_release: True
TextInput:
id: a
font_size: 25
password: True
pos_hint: {"x":0.5, "y":0.5}
size_hint: 0.3,0.2
text: "Insert Side A here"
Button:
id: adds
background_color: 0,0,1,1
color: 0,1,0,1
font_size: 25
on_release: root.add()
pos_hint: {"x":0, "y":0}
size_hint: 0.3,0.2
text: "plus"
Button:
color: 0,1,0,1
background_color: 0,0,1,1
font_size: 25
size_hint: 0.3,0.2
text: "Back Home"
on_release: app.root.current = "main"
pos_hint: {"right":1, "top":1}
Try placing the CheckBox in a Widget and it works. I mean:
FloatLayout:
Widget:
CheckBox:
pos_hint: {"x":0.2, "y":0.2}
on_release: True
TextInput:
id: a
font_size: 25
password: True
pos_hint: {"x":0.5, "y":0.5}
size_hint: 0.3,0.2
text: "Insert Side A here"
Button:
id: adds
background_color: 0,0,1,1
color: 0,1,0,1
font_size: 25
on_release: root.add()
pos_hint: {"x":0, "y":0}
size_hint: 0.3,0.2
text: "plus"
of course it ruins your layout but it solves the problem you are having.