'How to import class application from another directory into tabbedpanel kivy
I have made a calculator application. I am trying to make a GUI with the use of kivy. I have a tabbedpanel, and I am having trouble importing the calculator app to the first tab in the tabbedpanel. These are the two files I am working with, the calulator.py and the panel.py. Thank you for any feedback.
calculator.py:
`import kivy
from kivy.app import App
# making of button to arrange me
from kivy.uix.gridlayout import GridLayout
# for the size of window
from kivy.config import Config
# Setting size to resizable
Config.set('graphics', 'resizable', 1)
Config.set('graphics', 'width', '400')
Config.set('graphics', 'height', '400')
# Creating Layout class
class CalcGridLayout(GridLayout):
# Function called when equals is pressed
def calculate(self, calculation):
if calculation:
try:
# Solve formula and display it in entry
# which is pointed at by display
self.display.text = str(eval(calculation))
except Exception:
self.display.text = "Error"
# Creating App class
class CalculatorApp(App):
def build(self):
return CalcGridLayout()
# creating object and running it
calcApp = CalculatorApp()
calcApp.run()`
panel.py:
'''
TabbedPanel
============
Test of the widget TabbedPanel.
'''
from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.lang import Builder
import sys
sys.path.append("../Python GUI")
from Calculator.calculator import *
Builder.load_string("""
<Test>:
size_hint: 1, 1
pos_hint: {'center_x': .5, 'center_y': .5}
do_default_tab: False
TabbedPanelItem:
text: 'Tab 1'
TabbedPanelItem:
text: 'Tab 2'
BoxLayout:
Label:
text: 'Second tab content area'
Button:
text: 'Button that does nothing'
TabbedPanelItem:
text: 'Tab 3'
RstDocument:
text:
'\\n'.join(("Hello world", "-----------",
"You are in the third tab."))
""")
class Test(TabbedPanel):
pass
class TabbedPanelApp(App):
def build(self):
return Test()
if __name__ == '__main__':
TabbedPanelApp().run()
I would like the calculator to show in the first tab
Solution 1:[1]
You can access the appclass in kv by using app. . So for example if you want to access the property name of the app class it would look like this in kv
text:app.name
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Guhan SenSam |
