OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Process finished with exit code -1073740791 (0xC0000409) -- issue in a basic weather app using Python/PYQT6

  • Thread starter Thread starter luis torres
  • Start date Start date
L

luis torres

Guest
I am new to programming and have been trying to learn API and Guis via python 3.12.4 and PYQT6 with help from ChatGPT and google. I am running into this error in PyCharm "Process finished with exit code -1073740791 (0xC0000409)", outside of pycharm it just restarts the shell. The GUI does come up but when i press submit with the city name is when the issue occurs. the code is the following:

Code:
import sys
from PyQt6.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QVBoxLayout, QHBoxLayout
import json
import requests

class MainWindow(QWidget):
    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):
        self.setWindowTitle('Weather Information')
        self.setGeometry(100, 100, 600, 300)  # Adjusted width for additional elements

        # Widgets for City and State entry
        label_city_state = QLabel('Please enter your City and State:')
        self.lineEdit_city = QLineEdit()
        self.lineEdit_state = QLineEdit()
        submit_button = QPushButton('Submit')


        # Layout for city/state entry
        layout_entry = QHBoxLayout()
        layout_entry.addWidget(label_city_state)
        layout_entry.addWidget(self.lineEdit_city)
        layout_entry.addWidget(self.lineEdit_state)
        layout_entry.addWidget(submit_button)

        # Main layout for the window
        layout_main = QVBoxLayout(self)
        layout_main.addLayout(layout_entry)

        # Connect button click event to a function
        submit_button.clicked.connect(self.submitClicked)

        # Initialize empty labels for weather information
        self.labels_results = {}

    def submitClicked(self):
        # Remove existing weather information labels if any
        for label in self.labels_results.values():
            label.deleteLater()

        # Clear the dictionary
        self.labels_results.clear()

        # Retrieve the text entered in self.lineEdit_city
        CITY_NAME = self.lineEdit_city.text()
        
        # Create and display labels for weather information
        self.labels_results['Current Temperature:'] = QLabel('Current Temperature:')
        self.labels_results['CITY NAME'] = QLabel('CITY NAME:')
        self.labels_results['REGION:'] = QLabel('REGION:')
        self.labels_results['Current Condition:'] = QLabel('Current Condition:')
        self.labels_results['Current Wind Speed:'] = QLabel('Current Wind Speed:')
        self.labels_results['Current Wind Direction:'] = QLabel('Current Wind Direction:')

        # API Query
        BASE_URL = "http://api.weatherapi.com/v1/current.json?"
        API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxx"

        COMPLETE_URL = BASE_URL + "key=" + API_KEY + "&q=" + CITY_NAME

        response = requests.get(COMPLETE_URL).json()

        CITY = response["location"]["name"]
        REGION = response["location"]["region"]
        LOCAL_TIME = response["location"]["localtime"]
        CURR_TEMP = response["current"]["temp_f"]
        CURR_DESC = response["current"]["condition"]["text"]
        CURR_WIND_DIR = response["current"]["wind_dir"]
        CURR_WINDS = response["current"]["gust_mph"]

        # Example: Populate weather information labels with dummy data
        self.labels_results['CITY NAME'].setText(f'City:{API_Request.CITY}')
        self.labels_results['REGION:'].setText(f'REGION:{API_Request.REGION}')
        self.labels_results['Current Temperature:'].setText(f'Current Temperature: {API_Request.CURR_TEMP}')
        self.labels_results['Current Condition:'].setText(f'Current Condition: {API_Request.CURR_DESC}')
        self.labels_results['Current Wind Speed:'].setText(f'Current Wind Speed: {API_Request.CURR_WINDS}')
        self.labels_results['Current Wind Direction:'].setText(f'Current Wind Direction: {API_Request.CURR_WIND_DIR}')

        # Layout for weather information
        layout_results = QVBoxLayout()

        for label in self.labels_results.values():
            layout_results.addWidget(label)

        # Add weather information layout to main layout
        layout_main = self.layout()
        layout_main.addLayout(layout_results)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainWindow = MainWindow()
    mainWindow.show()
    sys.exit(app.exec())

I have tried googling but i have hit a roadblock due to my inexperience. The idea is that when you start the app you will be asked a city. You enter the city and press submit. when you press submit its suppose to start the API query and output the results to the labels. the App works to the part where i press submit which I then get this error. I believe I am missing something but unsure what that something is. Any help or references would be greatly appreciated. Thanks,
<p>I am new to programming and have been trying to learn API and Guis via python 3.12.4 and PYQT6 with help from ChatGPT and google. I am running into this error in PyCharm "Process finished with exit code -1073740791 (0xC0000409)", outside of pycharm it just restarts the shell. The GUI does come up but when i press submit with the city name is when the issue occurs. the code is the following:</p>
<pre><code>
import sys
from PyQt6.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QVBoxLayout, QHBoxLayout
import json
import requests

class MainWindow(QWidget):
def __init__(self):
super().__init__()

self.initUI()

def initUI(self):
self.setWindowTitle('Weather Information')
self.setGeometry(100, 100, 600, 300) # Adjusted width for additional elements

# Widgets for City and State entry
label_city_state = QLabel('Please enter your City and State:')
self.lineEdit_city = QLineEdit()
self.lineEdit_state = QLineEdit()
submit_button = QPushButton('Submit')


# Layout for city/state entry
layout_entry = QHBoxLayout()
layout_entry.addWidget(label_city_state)
layout_entry.addWidget(self.lineEdit_city)
layout_entry.addWidget(self.lineEdit_state)
layout_entry.addWidget(submit_button)

# Main layout for the window
layout_main = QVBoxLayout(self)
layout_main.addLayout(layout_entry)

# Connect button click event to a function
submit_button.clicked.connect(self.submitClicked)

# Initialize empty labels for weather information
self.labels_results = {}

def submitClicked(self):
# Remove existing weather information labels if any
for label in self.labels_results.values():
label.deleteLater()

# Clear the dictionary
self.labels_results.clear()

# Retrieve the text entered in self.lineEdit_city
CITY_NAME = self.lineEdit_city.text()

# Create and display labels for weather information
self.labels_results['Current Temperature:'] = QLabel('Current Temperature:')
self.labels_results['CITY NAME'] = QLabel('CITY NAME:')
self.labels_results['REGION:'] = QLabel('REGION:')
self.labels_results['Current Condition:'] = QLabel('Current Condition:')
self.labels_results['Current Wind Speed:'] = QLabel('Current Wind Speed:')
self.labels_results['Current Wind Direction:'] = QLabel('Current Wind Direction:')

# API Query
BASE_URL = "http://api.weatherapi.com/v1/current.json?"
API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxx"

COMPLETE_URL = BASE_URL + "key=" + API_KEY + "&q=" + CITY_NAME

response = requests.get(COMPLETE_URL).json()

CITY = response["location"]["name"]
REGION = response["location"]["region"]
LOCAL_TIME = response["location"]["localtime"]
CURR_TEMP = response["current"]["temp_f"]
CURR_DESC = response["current"]["condition"]["text"]
CURR_WIND_DIR = response["current"]["wind_dir"]
CURR_WINDS = response["current"]["gust_mph"]

# Example: Populate weather information labels with dummy data
self.labels_results['CITY NAME'].setText(f'City:{API_Request.CITY}')
self.labels_results['REGION:'].setText(f'REGION:{API_Request.REGION}')
self.labels_results['Current Temperature:'].setText(f'Current Temperature: {API_Request.CURR_TEMP}')
self.labels_results['Current Condition:'].setText(f'Current Condition: {API_Request.CURR_DESC}')
self.labels_results['Current Wind Speed:'].setText(f'Current Wind Speed: {API_Request.CURR_WINDS}')
self.labels_results['Current Wind Direction:'].setText(f'Current Wind Direction: {API_Request.CURR_WIND_DIR}')

# Layout for weather information
layout_results = QVBoxLayout()

for label in self.labels_results.values():
layout_results.addWidget(label)

# Add weather information layout to main layout
layout_main = self.layout()
layout_main.addLayout(layout_results)


if __name__ == '__main__':
app = QApplication(sys.argv)
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec())



</code></pre>
<p>I have tried googling but i have hit a roadblock due to my inexperience. The idea is that when you start the app you will be asked a city. You enter the city and press submit. when you press submit its suppose to start the API query and output the results to the labels. the App works to the part where i press submit which I then get this error. I believe I am missing something but unsure what that something is. Any help or references would be greatly appreciated.
Thanks,</p>
 

Latest posts

S
Replies
0
Views
1
Safwan Aipuram
S
Top