Код: Выделить всё
from textual.app import App, ComposeResult
from textual.widgets import Static, Input
class Location:
def __init__(self, search_input: str) -> None:
"""
Initialize the search_input variable.
"""
self.__search_input = search_input
@property
def search_input(self) -> str:
"""
Get the search_input property.
"""
return self.__search_input
@search_input.setter
def search_input(self, newSearchInput: str) -> None:
"""
Set the value of the search_input.
"""
self.__search_input = newSearchInput
def getLocation(search_input) -> list[str]:
"""
Function to define the location.
"""
if search_input != "":
LOCATION = str(search_input)
city = LOCATION
state = ""
country = ""
if len(LOCATION) >= 2:
state = LOCATION[1]
if len (LOCATION) == 3:
country = LOCATION[2]
else:
city = "Test"
state = ""
country = ""
if state == "" and country == "":
LOCATION = [city]
elif state != "" and country == "":
LOCATION = [city, ", ", state]
elif state == "" and country != "":
LOCATION = [city, ", ", "", "", country]
elif state != "" and country != "":
LOCATION = [city, ", ", state, ", ", country]
return LOCATION
class WeatherApp(App):
"""
The main class for the weather app.
"""
def compose(self) -> ComposeResult:
"""
Compose the app.
"""
input = Input(value="",placeholder="Enter a location...")
yield input
location = Location(Input.value)
LOCATION = location.getLocation()
output = Static(LOCATION[0])
yield output
if __name__ == "__main__":
"""
Execute the app.
"""
app = WeatherApp()
app.run()
Как я могу изменить свой код, чтобы можно было правильно получить доступ к значению входной строки?
Подробнее здесь: https://stackoverflow.com/questions/782 ... nput-value
Мобильная версия