Kyvi
In [1]:
Copied!
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
[INFO ] [Logger ] Record log in C:\Users\00661711722\.kivy\logs\kivy_24-11-08_4.txt
[INFO ] [deps ] Successfully imported "kivy_deps.angle" 0.4.0
[INFO ] [deps ] Successfully imported "kivy_deps.glew" 0.3.1
[INFO ] [deps ] Successfully imported "kivy_deps.sdl2" 0.7.0
[INFO ] [Kivy ] v2.3.0
[INFO ] [Kivy ] Installed at "c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\kivy\__init__.py"
[INFO ] [Python ] v3.12.7 (tags/v3.12.7:0b05ead, Oct 1 2024, 03:06:41) [MSC v.1941 64 bit (AMD64)]
[INFO ] [Python ] Interpreter at "c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Scripts\python.exe"
[INFO ] [Logger ] Purge log fired. Processing...
[INFO ] [Logger ] Purge finished!
[INFO ] [Factory ] 195 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] GLEW initialization succeeded
[INFO ] [GL ] Backend used <glew>
[INFO ] [GL ] OpenGL version <b'4.6.0 NVIDIA 556.12'>
[INFO ] [GL ] OpenGL vendor <b'NVIDIA Corporation'>
[INFO ] [GL ] OpenGL renderer <b'NVIDIA T1000/PCIe/SSE2'>
[INFO ] [GL ] OpenGL parsed version: 4, 6
[INFO ] [GL ] Shading version <b'4.60 NVIDIA'>
[INFO ] [GL ] Texture max size <32768>
[INFO ] [GL ] Texture max units <32>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
In [2]:
Copied!
class Retangulo:
def __init__(self, base, altura):
self.base = base
self.altura = altura
def calcular_area(self):
return self.base * self.altura
class Retangulo:
def __init__(self, base, altura):
self.base = base
self.altura = altura
def calcular_area(self):
return self.base * self.altura
In [3]:
Copied!
class CalculadoraAreaApp(App):
def build(self):
layout = BoxLayout(orientation='vertical')
self.base_input = TextInput(multiline=False)
self.altura_input = TextInput(multiline=False)
self.resultado_label = Label(text='Resultado:')
calcular_button = Button(text='Calcular')
calcular_button.bind(on_press=self.calcular_area)
layout.add_widget(self.base_input)
layout.add_widget(self.altura_input)
layout.add_widget(calcular_button)
layout.add_widget(self.resultado_label)
return layout
def calcular_area(self, instance):
try:
base = float(self.base_input.text)
altura = float(self.altura_input.text)
retangulo = Retangulo(base, altura)
resultado = retangulo.calcular_area()
self.resultado_label.text = f'A área é: {resultado}'
except ValueError:
self.resultado_label.text = 'Digite valores numéricos.'
class CalculadoraAreaApp(App):
def build(self):
layout = BoxLayout(orientation='vertical')
self.base_input = TextInput(multiline=False)
self.altura_input = TextInput(multiline=False)
self.resultado_label = Label(text='Resultado:')
calcular_button = Button(text='Calcular')
calcular_button.bind(on_press=self.calcular_area)
layout.add_widget(self.base_input)
layout.add_widget(self.altura_input)
layout.add_widget(calcular_button)
layout.add_widget(self.resultado_label)
return layout
def calcular_area(self, instance):
try:
base = float(self.base_input.text)
altura = float(self.altura_input.text)
retangulo = Retangulo(base, altura)
resultado = retangulo.calcular_area()
self.resultado_label.text = f'A área é: {resultado}'
except ValueError:
self.resultado_label.text = 'Digite valores numéricos.'
In [4]:
Copied!
if __name__ == '__main__':
CalculadoraAreaApp().run()
if __name__ == '__main__':
CalculadoraAreaApp().run()
---------------------------------------------------- OSError Traceback (most recent call last) Cell In[4], line 2 1 if __name__ == '__main__': ----> 2 CalculadoraAreaApp().run() File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\kivy\app.py:955, in App.run(self) 952 def run(self): 953 '''Launches the app in standalone mode. 954 ''' --> 955 self._run_prepare() 956 runTouchApp() 957 self._stop() File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\kivy\app.py:924, in App._run_prepare(self) 922 if not self.built: 923 self.load_config() --> 924 self.load_kv(filename=self.kv_file) 925 root = self.build() 926 if root: File c:\Users\00661711722\Documents\PBE_24.2_8002\.venv\Lib\site-packages\kivy\app.py:677, in App.load_kv(self, filename) 675 else: 676 try: --> 677 default_kv_directory = dirname(getfile(self.__class__)) 678 if default_kv_directory == '': 679 default_kv_directory = '.' File C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.2032.0_x64__qbz5n2kfra8p0\Lib\inspect.py:923, in getfile(object) 921 return module.__file__ 922 if object.__module__ == '__main__': --> 923 raise OSError('source code not available') 924 raise TypeError('{!r} is a built-in class'.format(object)) 925 if ismethod(object): OSError: source code not available