D
D
Dirollo2020-07-23 19:22:35
Python
Dirollo, 2020-07-23 19:22:35

How can I add screen to the toolbar(kivymd) so that it hides the toolbar itself and opens a new screen?

The name of the nifiga is not clear, now I will explain. I have a code (it will be below), and there I added Tabs, I also added the settings button there on the right, and I need the settings screen to open after clicking, and the toolbar was not visible, which I will finish later, but it doesn’t work

import pyowm
from pyowm.owm import OWM
from pyowm.utils.config import get_config_from

import subprocess

import sys
import requests
from bs4 import BeautifulSoup as BS

from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import StringProperty
from kivy.core.text import LabelBase

from kivymd.uix.snackbar import Snackbar
from kivymd.font_definitions import theme_font_styles
from kivymd.uix.button import MDFlatButton
from kivymd.uix.button import MDIconButton
from kivymd.app import MDApp
from kivymd.uix.tab import MDTabsBase


config_dict = get_config_from('config.json')
owm = pyowm.OWM('ed3d1e950f0d1e73b26cfd7f55fbb4f9', config_dict)

mgr = owm.weather_manager()
sm = ScreenManager()

kv = """
BoxLayout:
    orientation: "vertical"

    MDToolbar:
        title: "Парсинг сайтів"
        title_font_style: 'Custom'
        md_font_style: 'FFont'
        
        MDIconButton:
      	icon: "settings"
   		 theme_text_color: "Custom" 
    		md_text_color: 0, 1, 1, 1
    		on_press: app.stgs()
      
    MDTabs:
        font_style: 'FFont'
        id: tab

<[email protected]>:
  font_size: '20sp'
  halign: 'right'
  valign: 'middle'
  text_size: self.size
  font_style: 'FFont'
  bold: True

<[email protected]>:
  font_size: '80sp'
  halign: 'left'
  valign: 'middle'
  font_style: 'FFont'
  bold: True
  
<ScreenManag>:
  wWindow:
  krvWindow:
  SettingsWindow:

<wWindow>:
  name: 'weather'
  FitImage:
    source: "Images/litev.jpg"
  FloatLayout:
      id: fl	
    MDIconButton:
      	icon: "check-bold"
      	pos_hint: {'y': .89, 'x': .75}
      	on_press: root.update()
      	
    MDLabel:
      id: error
      font_style: 'FFont'
      text: ""
      pos_hint: {'y': .365, 'x': .4}
  FloatLayout:
    md_bg_color: 1, .4, .1, 1
    MDTextField:
      	hint_text: "Назва міста/села"
      	fill_color: 0, 0, 0, .4
      	color_mode: 'custom'
      	line_color_focus: 0, 1, 1, 1
      	text: ""
      	mode: "rectangle"
      	id: ccity
      	pos_hint: {'y': .90, 'x': .3}
      	size_hint: .4, .067
      	current_hint_text_color: 1, 1, .3, .8
  MDGridLayout:
    cols: 2
    size_hint: .9, .8
    md_bg_color: 0, .8, 1, .6
    pos_hint: {'y': .03, 'x': .05}
    MDBoxLayout:
        spacing: 130
        orientation: 'vertical'
        padding: [100, 0, 0, 0]
        Lblt:
        	id: label
            text: "Температура Зараз"
        Lblt:
            id: label2
            text: "Мін/Макс Температура Сьогодні"
        Lblt:
            id: label3
            text: "Вологість(%)"
        Lblt:
            id: label4
            text: "Небo"
    MDBoxLayout:
      spacing: 130
      orientation: 'vertical'
      padding: [0, 0, 90, 0]
      Lblv:
        	id: res
        	text: "0.0"
        Lblv:
            id: res1
            text: "0/0"
        Lblv:
            id: res2
            text: "0%"
        Lblv:
            id: res3
            text: "None"
            text_color: 1, 1, 0, 1 
          
  MDGridLayout:
    rows: 4
    size_hint_y: .8
    spacing: 210
    padding: 50
    pos_hint: {'y': .03, 'x': .03}
    MDIcon:
      icon: "temperature-celsius"
    MDIcon:
      icon: "thermometer-lines"
    MDIcon:
      icon: "water-percent"
      MDIcon:
      icon: "weather-partly-cloudy"
      
<krvWindow>:
  name: 'krv'
  BoxLayout:
    MDIcon:
      icon: "youtube"
<SettingsWindow>:
  name: 'stg'
  BoxLayout:
    MDIcon:
      icon: "google"
"""

class krvWindow(MDTabsBase, Screen):
  pass
  
class SettingsWindow(Screen):
  pass

class wWindow(MDTabsBase, Screen):
  def update(self):
      ciity = open('city.txt', 'r')
      if (self.ids.ccity.text == ""):
      	city = ciity.read()
      	self.ids.ccity.text = str(city)
      	ciity.close()
      else:
      	city = str(self.ids.ccity.text)
      rt = 'https://sinoptik.ua/погода-' + str(city)
      r = requests.get(rt)
      html = BS(r.content, 'html.parser')
      try:
        for elms in html.select('#content'):
        	t_min = elms.select('.temperature .min > span')[0].text
        	t_max = elms.select('.temperature .max > span')[0].text
        observation = mgr.weather_at_place(city)
        w = observation.weather
        l = w.temperature('celsius')['temp']
        nt = w.temperature('celsius')['temp_min']
        xt = w.temperature('celsius')['temp_max']
        temp = str(l) + " °C"
        answer = w.detailed_status
        hum = w.humidity
        mmr = str(hum) + "%"
        self.ids.res.text = str(temp)
        self.ids.res1.text = str(t_min + "/" + t_max)
        self.ids.res2.text = str(mmr)
        self.ids.res3.text = str(answer)
        self.ids.error.text = ""
        cwity = open('city.txt', 'w')
        cwity.write(city)
        cwity.close()
      except:
      	self.ids.res.text = str("0.0")
      	self.ids.res1.text = str("0/0")
      	self.ids.res2.text = str("0%")
      	self.ids.res3.text = str("None")
      	self.ids.error.text = "Помилка"
      	Snackbar(text = "Помилка, введіть правильну назву міста або села").show()

class ScreenManag(ScreenManager):
  pass

class MainWindow(MDApp):
    n = 3
    def build(self):
        self.theme_cls.primary_palette = "Teal"
        LabelBase.register(
            name="DataFont",
            fn_regular="Fonts/19439.ttf")
        theme_font_styles.append('DataFont')
        self.theme_cls.font_styles["DataFont"] = [
            "DataFont",
            18,
            False,
            0.15,
        ]
        LabelBase.register(
            name="FFont",
            fn_regular="Fonts/18685.ttf")
        theme_font_styles.append('FFont')
        self.theme_cls.font_styles["FFont"] = [
            "FFont",
            24,
            False,
            0.15,
        ]
        return Builder.load_string(kv)

    def on_start(self):
    	sm.add_widget(wWindow(name='weather'))
    	sm.add_widget(krvWindow(name='krv'))
    	sm.add_widget(SettingsWindow(name='stg'))
    	nms = ["Курс биткоина", "	Курс доллара и эвро", "Коронавирус", "Погода"]
    	w1 = self.root.ids.tab.add_widget(wWindow(text=nms[self.n]))
    	self.n -= 1
    	w2 = self.root.ids.tab.add_widget(krvWindow(text=nms[self.n]))
    	pass
    def stgs(self):
    	sm.current = 'stg'
    	

if __name__ == '__main__':
  MainWindow().run()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question