I'm working on a project and i'm having trouble openning the spinner widget from kivy. I couldn't find any answer surfing the internet so I came here :)
I tried using the Float Layout insted of Grid layout and it didn't work either. Using kivy==1.11.1 (didn't work neither in 2.0.0rc1 nor 1.11.0)
UI.py
import kivy
kivy.require('1.11.1')
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty
from kivy.uix.button import Button
from kivy.core.window import Window
Window.clearcolor = (1, 1, 1, 1)
from tkinter import Tk
from tkinter.filedialog import askopenfilename
class CustRedButton(Button):
pass
class MainScreen(Screen):
def OpenData(self):
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
dir = askopenfilename(title='Open File', filetypes=(('CSV files', '*.csv'),))
if dir:
self.DataFileDir=dir
def toSettings(self):
try:
if self.DataFileDir:
pass
self.manager.current = 'settings'
except Exception as e:
if isinstance(e, AttributeError):
print('Got No Data')
self.manager.current = 'settings'
else:
print(e)
class SettingsScreen(Screen):
def __init__(self, **kwargs):
super(SettingsScreen, self).__init__(**kwargs)
self.spinner_values = ('House', 'Home', 'Car', 'Kivy')
def toMain(self):
try:
self.manager.current = 'main'
except Exception as e:
print(e)
def on_spinner_select(self, text):
print(text)
class ScreenManagment(ScreenManager):
main_screen= ObjectProperty(None)
settings_screen= ObjectProperty(None)
presentation= Builder.load_file('main.kv')
class MainApp(App):
def build(self):
return presentation
def runUI():
MainApp().run()
if __name__ == '__main__':
runUI()
and the main.kv:
#: import NoTransition kivy.uix.screenmanager.NoTransition
<Button>:
font_size: root.width*0.1
size_hint: 0.2,0.17
color: 0,0,0,1
background_normal: ''
background_color: 0.8,0.8,0.8,1
<CustRedButton>:
font_size: root.width*0.19
size_hint: 0.1,0.1
color: 0,0,0,1
background_normal: ''
background_color: 1,0.1,0.1,1
<Label>:
color: 0,0,0,1
ScreenManagment:
id: screen_manager
main_screen: main_screen
settngs_screen: settings_screen
transition: NoTransition()
MainScreen:
name: 'main'
id: main_screen
manager: screen_manager
SettingsScreen:
name: 'settings'
id: settings_screen
manager: screen_manager
<MainScreen>:
BoxLayout:
orientation:'horizontal'
FloatLayout:
Button:
pos_hint: {'x':0.55,'top':0.6}
on_press: root.toSettings()
text: 'Go To Settings'
Button:
pos_hint: {'x':0.25,'top':0.6}
text: 'Open Data'
on_release: root.OpenData()
<SettingsScreen>:
BoxLayout:
orientation:'horizontal'
FloatLayout:
CustRedButton:
pos_hint:{'x':0, 'y':0}
on_press: root.toMain()
text: 'To Main'
GridLayout:
cols:2
pos_hint: {'x':-0.1, 'y':0.6}
size_hint: 1, 0.2
Label:
text:"Select"
Spinner:
pos_hint: {'center': (.7, .7)}
text: root.spinner_values[0]
values: root.spinner_values
on_text: root.on_spinner_select(text)
background_color: 0.5,0.5,0.5,1
All of the other widgets work fine, and the spinner gets the 'spinner_values' from the __ init __ fine I actually have no clue why I can see the spinner but not open it to select a value.
p.s. I'm new to StackOverflow, so if I didn't put enough info tell me and I'll add it