My mapview app is not loading the image and I don't know why
Check and make sure your internet connection is working fast
Make sure you have "requests" module
Try out this example, make sure you have already installed all kivy_garden modules
Try this code:
import sys
from kivy.base import runTouchApp
from kivy.lang import Builder
if __name__ == '__main__' and __package__ is None:
from os import path
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
root = Builder.load_string(
"""
#:import sys sys
#:import MapSource kivy_garden.mapview.MapSource
MapView:
lat: 50.6394
lon: 3.057
zoom: 13
map_source: MapSource(sys.argv[1], attribution="") if len(sys.argv) > 1 else "osm"
MapMarkerPopup:
lat: 50.6394
lon: 3.057
popup_size: dp(230), dp(130)
Bubble:
BoxLayout:
orientation: "horizontal"
padding: "5dp"
AsyncImage:
source: "http://upload.wikimedia.org/wikipedia/commons/9/9d/France-Lille-VieilleBourse-FacadeGrandPlace.jpg"
mipmap: True
Label:
text: "[b]Lille[/b]\\n1 154 861 hab\\n5 759 hab./km2"
markup: True
halign: "center"
"""
)
runTouchApp(root)
Related
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivymd.uix.screen import MDScreen
from kivymd.app import MDApp
KV = '''
<Screen3>
MDBoxLayout:
orientation:'vertical'
MDToolbar:
title: "Home"
left_action_items: [["menu", lambda x: app.callback()]]
AnchorLayout:
anchor_x: 'center'
anchor_y: 'top'
ScrollView:
size_hint:0.8,0.7
do_scroll_x:False
do_scroll_y:True
GridLayout:
size_hint_y:None
height:self.minimum_height
cols:1
spacing:10
padding:10
id:gr
'''
Builder.load_string(KV)
class Screen3(MDScreen):
pass
class Test(MDApp):
def build(self):
screen_manager = ScreenManager()
screen_manager.add_widget(Screen3(name='screen3'))
return screen_manager
Test().run()
This is my basic code right now. For some reason the reference error is caused by the left_action_items option. When I remove it the code works. I honestly have no idea what causes this issue.
I'm very new at Kivy. I'm following an example at kivy docs where I came across this following code. bBut it's not working properly.
first.py
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
class LoginScreen(GridLayout):
pass
class MyApp(App):
def build(self):
return LoginScreen()
if __name__ == '__main__':
MyApp().run()
my.kv
#:kivy 2.0
<LoginScreen>:
f_username: username
f_password: password
GridLayout:
rows: 2
cols: 2
padding: 10
spacing: 10
Label:
text: "Username"
TextInput:
id: username
multiline: False
Label:
text: "Password"
TextInput:
id: password
password: True
multiline: False
This code works fine if i remove the LoginScreen class from both kivy and python file. Like
class MyApp(App):
def build(self):
return
and
#:kivy 2.0
f_username: username
f_password: password
GridLayout:
rows: 2
...
Can anyone help me to figure out what's happening?
class LoginScreen(GridLayout):
pass
This means that when you create an instance with the LoginScreen class, the instance becomes GridLayout.
# GridLayout
<LoginScreen>:
f_username: username
f_password: password
# Another GridLayout!
GridLayout:
...
The LoginScreen is already based on GridLayout, but you are trying to add another gridlayout to the class. In this case, rows and cols are not defined on the outmost gridlayout.
#:kivy 2.0
<LoginScreen>:
f_username: username
f_password: password
rows: 2
cols: 2
padding: 10
spacing: 10
Label:
text: "Username"
TextInput:
id: username
multiline: False
Label:
text: "Password"
TextInput:
id: password
password: True
multiline: False
Removing the duplicate layout will fix the problem.
I'm trying to make the button click on_release: app.proximo () have the action to go to the next card MDFloatLayout, but I'm not getting it, could someone help me how could it work?
Below the main.py file, where to start the app, main.kv file, where is the main app and finally the dashboard.kv file where I am calling my card inside the app
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
class DashBoard(Screen):
pass
class FirstScreen(Screen):
pass
class Lavanderia(MDApp):
def build(self):
self.title="Texto Titulo"
self.theme_cls.primary_palette = "LightBlue"
return Builder.load_file("main.kv")
def proximo(self):
self.root.ids.carousel.load_next(mode="proximo")# Próximo Card
def fecharApp(self):
self.stop()# Fecha Aplicativo
Lavanderia().run()
#:import rgba kivy.utils.get_color_from_hex
#: include dashboard.kv
#: include firstscreen.kv
NavigationLayout:
id: nav_layout
ScreenManager:
Screen:
BoxLayout:
orientation:'vertical'
MDToolbar:
title: app.title
elevation:10
left_action_items:[["menu", lambda x: nav_drawer.set_state()]]
ScreenManager:
id: screen_manager
DashBoard:
id:dashboard
name:"dashboard"
FirstScreen:
id:first_screen
name:"first_screen"
MDNavigationDrawer:
id: nav_drawer
BoxLayout:
orientation:'vertical'
padding:"8dp"
spacing:"8dp"
Image:
pos_hint:{"x":.24,"y":.0}
size_hint: None, None
size:dp(146), dp(158)
source:"images/logo.png"
ScrollView:
MDList:
OneLineIconListItem:
text:"Tela 1"
on_release:
screen_manager.current = "dashboard"
nav_drawer.set_state()
IconLeftWidget:
icon:"dishwasher"
OneLineIconListItem:
text:"Tela 2"
on_release:
screen_manager.current = "first_screen"
nav_drawer.set_state()
IconLeftWidget:
icon:"dishwasher"
<DashBoard>:
MDFloatLayout:
MDCard:
size_hint: dp(.45), dp(.8)
pos_hint:{"center_x": .5, "center_y": .5}
Carousel:
id:carousel
MDFloatLayout:
MDTextField:
hint_text:"Texto 1"
size_hint_x:dp(.8)
pos_hint:{"center_x": .5, "center_y": .48}
MDRaisedButton:
text: "Proximo"
size_hint_x:dp(.8)
pos_hint:{"center_x":.5,"center_y":.2}
on_release: app.proximo() # Proximo step
MDFloatLayout:
MDLabel:
text:"Texto Final Conclusão"
theme_text_color:"Custom"
bold:True
pos_hint:{"center_x":.68,"center_y":.5}
font_style:"H5"
MDRaisedButton:
text: "Fechar Aplicativo"
text_color:rgba("#00FF69")
size_hint_x:dp(.8)
pos_hint:{"center_x":.5,"center_y":.4}
md_bg_color:rgba("#333333")
on_release: app.fecharApp() #fechar Aplicativo
You are trying to ger the carrousel through the root screen, but it is inside the dashboard screen.
So you will have to navigate there first, and only then you can call your function.
def proximo(self):
dashboard = self.root.ids.dashboard
carousel = dashboard.ids.carousel
carousel.load_next(mode="proximo")
# Same as
# self.root.ids.dashboard.ids.carousel.load_next(mode="proximo")
I'm new to kivy and I want to change my screen by clicking the image. I used the ButtonBehavior and call the on_press method of my class ImageButton but I can't figure it out what code to put. I tried on_press: screen_manager.current = 'window1' on my kivy file but its not working
Python Code
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.image import Image
from kivy.uix.behaviors import ButtonBehavior
class Window1(Screen):
pass
class Window2(Screen):
pass
class WindowManager(ScreenManager):
pass
class ImageButton(ButtonBehavior, Image):
def on_press(self):
# what to call
class Phone(FloatLayout):
pass
class MyApp(App):
def build(self):
return Phone()
if __name__ == '__main__':
MyApp().run()
kv file
<Phone>:
AnchorLayout:
anchor_x: 'center'
anchor_y: 'top'
WindowManager:
id: screen_manager
size_hint: 1, 0.9
anchor_y: 'top'
transition: FadeTransition()
Window1:
Window2:
AnchorLayout:
anchor_x: 'center'
anchor_y: 'bottom'
BoxLayout:
canvas:
Color:
rgba: 228, 241, 254, 1
Rectangle:
size: self.size
orientation: 'horizontal'
size_hint: 1, .1
ImageButton:
source: 'pic1.png'
on_press: self.on_press()
ImageButton:
source: 'pic2.png'
on_press: self.on_press()
<Window1>:
name: 'window1'
Label:
text: 'Window1'
<Window2>:
name: 'window2'
Label:
text: 'Window2'
Some one help me on this.. what im missing is in my kv file i should put
on_press: app.root.ids._screen_manager.current = 'window1'
Here is the explanation
When the kv code is parsed, the id fields go into a dict called ids, that stores pointers to the widget objects.
Each kivy rule has a sperate name space for ids.
Breaking it down:
app.root.ids.screen_manager
app is your app
root is the root widget, Phone
ids is the dict of ids defined at the root level
Credit for Elliot Garbus
I am new to kivy.
I have created a login page with 2 text fields. I am now trying to pass the variables to the next page, which will use a ssh client for python to connect to a server. However, when I run the program, it seems that the method I am calling in my second screen does not even run, as none of the debugging output shows up.
I have tried a few methods of passing in variables into a function of a different class, and temporarily I have set upon using global variables. I am sure there is an easier or better way, but I can't get the function to run in the first place.
main.py
from kivy.config import Config
Config.set('graphics', 'resizable', False)
from kivy.app import App
from kivy.properties import StringProperty
from kivy.core.window import Window
from kivy.uix.screenmanager import ScreenManager, Screen, SlideTransition
import csv
import paramiko
#import os
global username
global password
def load_csv(filepath):
with open(filepath, newline='') as csvfile:
file_array = list(csv.reader(csvfile))
csvfile.close()
return file_array
class Connect(Screen):
Window.size = (600, 300)
def routine(self):
host = 'titanrobotics.ddns.net'
port = 60022
print(username, password)
self.ids.status.text = "connecting"
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
self.ids.status.text = "attempting to connect to " + host
ssh.connect(host, port, username, password)
yield ssh
self.ids.status.text = "connected to " + host
finally:
ssh.close()
self.ids.status.text = "connection failed"
#print("here")
#ssh = loginroutine(username, password)
class Login(Screen):
Window.size = (600, 300)
def do_login(self, loginText, passwordText):
app = App.get_running_app()
username = loginText
password = passwordText
self.manager.transition = SlideTransition(direction = "left")
self.manager.current = "connect"
def resetForm(self):
self.ids['login'].text = ""
self.ids['password'].text = ""
class BrummetApp(App):
username = StringProperty(None)
password = StringProperty(None)
title = 'Brummet Client v ' + load_csv("data/meta")[0][1]
def build(self):
manager = ScreenManager()
manager.add_widget(Login(name = 'login'))
manager.add_widget(Connect(name = 'connect'))
return manager
if __name__ == '__main__':
BrummetApp().run()
brummet.kv
<Login>:
BoxLayout
id: login_layout
orientation: 'vertical'
padding: [10,10,10,10]
spacing: 10
BoxLayout:
orientation:'vertical'
padding: [0,0,0,0]
spacing: 0
Label:
id: title
text: 'Brummet Client'
halign: 'center'
valign: 'middle'
font_size: 24
Label:
text: 'Please log in with IMSA SLURM credentials'
halign: 'center'
valign: 'middle'
spacing: -20
font_size: 24
BoxLayout:
orientation: 'vertical'
Label:
text: 'Username'
font_size: 18
halign: 'left'
text_size: root.width-20, 0
TextInput:
id: username
multiline: False
font_size: 16
write_tab: False
BoxLayout:
orientation: 'vertical'
Label:
text: 'Password'
halign: 'left'
font_size: 18
text_size: root.width-20, 0
TextInput:
id: password
multiline: False
password: True
font_size: 16
write_tab: False
Button:
text: 'Log In'
font_size: 24
on_press:
root.do_login(username.text, password.text)
<Connect>:
on_enter:
root.routine()
BoxLayout:
orientation: 'vertical'
padding: [0,125,0,125]
spacing: 0
Label:
text:'Logging In'
font_size: 24
halign: 'center'
valign: 'middle'
Label:
id: status
test:''
font_size: 16
halign: 'center'
valign: 'middle'
It seems that loading the Connect class is fine, however I am unable to run the .routine() method on_enter.
The yield ssh is preventing the Connect.routine() from executing. Try comment it off.