from kivy.app import Appfrom kivy.clock import Clockfrom kivy.core.window import Windowfrom kivy.lang import Builderfrom kivy.properties import NumericProperty, ObjectProperty, StringPropertyfrom kivy.uix.floatlayout import FloatLayoutfrom kivy.uix.popup import Popup
Builder.load_string("""
#:kivy 1.11.1
<MainScreen>:
input_text: input_text.text
BoxLayout: orientation: 'vertical'
TextInput: id: input_text Button: text: 'Open popup' on_release: root.do_stuff()
<PopupScreen>
BoxLayout: orientation : 'vertical' size: root.size pos: root.pos Label: size_hint_y: 0.3 text: 'Message' Button: size_hint_y: 0.5 text: 'Print' on_release: root.print_text() Button: size_hint_y: 0.2 text: 'Cancel' on_release: root.cancel()
""")
class PopupScreen(FloatLayout):
print_text = ObjectProperty(None) cancel = ObjectProperty(None)
class MainScreen(FloatLayout):
Window.size = (600, 400) input_text = StringProperty(None) def dismiss_popup(self): self._popup.dismiss() Window.size = self.current_size # return window to adjusted size
def print_text(self):
print("output: " + self.input_text)
def open_popup(self): # remember main screen window size self.current_size = Window.size # set popup window size Window.size = (400, 400)
# open popup content = PopupScreen(print_text=self.print_text, cancel=self.dismiss_popup) self._popup = Popup(title="Popup", content=content) print("check3: " + self.input_text) Clock.schedule_once(lambda dt: self._popup.open(), 0.5) def add_suffix(self): # refresh text (to prevent _suffix_suffix when rerun without editing text) self.input_text = self.ids.input_text.text # add suffix self.input_text = self.input_text + '_suffix'
print("check2: " + self.input_text)
Clock.schedule_once(lambda dt: self.open_popup(), 0.5)
def do_stuff(self): '''Action when "Run" button is pressed''' #do stuff here print("check1: " + self.input_text)
self.add_suffix()
# define Base Class of Kivy Appclass TestApp(App):
def build(self): return MainScreen()
# run programif __name__ == '__main__': TestApp().run()
There were are few things I changed below, the issue was related to a line in the kv file..
input_text: input_text.text
from kivy.app import App
from kivy.clock import Clock
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.properties import NumericProperty, ObjectProperty, StringProperty
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.popup import Popup
Builder.load_string(
"""
#:kivy 1.11.1
<MainScreen>:
#input_text: input_text.text # Not sure what you are trying to do here...
)
(FloatLayout):
input_text = StringProperty('') # removed None
#Window.size = (600, 400) # Moved to build, this code was not in a method.
def dismiss_popup(self):
self._popup.dismiss()
Window.size = self.current_size # return window to adjusted size
def print_text(self):
print("output: " + self.input_text)
def open_popup(self):
# remember main screen window size
self.current_size = Window.size
# set popup window size
Window.size = 400, 400
# open popup
content = PopupScreen(print_text=self.print_text, cancel=self.dismiss_popup)
self._popup = Popup(title="Popup", content=content)
print("check3: " + self.input_text)
Clock.schedule_once(lambda dt: self._popup.open(), 0.5)
def add_suffix(self):
# refresh text (to prevent _suffix_suffix when rerun without editing text)
self.input_text = self.ids.input_text.text
# add suffix
self.input_text = self.input_text + '_suffix'
print("check2: " + self.input_text)
Clock.schedule_once(lambda dt: self.open_popup(), 0.5)
def do_stuff(self):
'''Action when "Run" button is pressed'''
# do stuff here
print("check1: " + self.input_text)
self.add_suffix()
# define Base Class of Kivy App
class TestApp(App):
def build(self
):
Window.size = 600, 400 # moved here
return MainScreen()
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/21943552-08b1-4f1c-aed2-b65e0d11a962o%40googlegroups.com.
input_text: input_text.text
from kivy.app import App
from kivy.core.window import Windowfrom kivy.lang import Builderfrom kivy.properties import NumericProperty, ObjectProperty, StringPropertyfrom kivy.uix.floatlayout import FloatLayoutfrom kivy.uix.popup import Popup
Builder.load_string("""
#:kivy 1.11.1
<MainScreen>:
input_text: input_text
input_text = ObjectProperty(None)
def dismiss_popup(self): self._popup.dismiss() Window.size = self.current_size # return window to adjusted size
def print_text(self):
print("output: " + self.modified_text)
def open_popup(self): # remember main screen window size self.current_size = Window.size # set popup window size Window.size = 400, 400
# open popup content = PopupScreen(print_text=self.print_text, cancel=self.dismiss_popup) self._popup = Popup(title="Popup", content=content)
self._popup.open() def add_suffix(self): # add suffix self.modified_text = self.input_text.text + '_suffix'
self.open_popup()
def do_stuff(self): '''Action when "Run" button is pressed''' # do stuff here
self.add_suffix()
# define Base Class of Kivy Appclass TestApp(App):
def build(self): Window.size = 600, 400
return MainScreen()
# run programif __name__ == '__main__': TestApp().run()
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.