I'm trying to get a PyQt lineEdit widget to place its' contents within a variable in the module 'followup' but for some reason the module does not recognize the PyQt MainWindow as being properly instantiated.
#workbot_main.py
import gspread
import os
import sys
sys.path.append(os.path.abspath(r"C:\Users\leamy\Desktop\work bot\workbot.py"))
sys.path.append(os.path.abspath(r"C:\Users\leamy\Desktop\work bot\initial.py"))
sys.path.append(os.path.abspath(r"C:\Users\leamy\Desktop\work bot\followup.py"))
import threading
import followup
import initial
from PyQt5 import QtWidgets
from PyQt5 import QtCore
from PyQt5.QtWidgets import QMainWindow, QApplication
from workbot import *
import workbot
#workbot.py is the QTdesigner file containing the widgets,
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
followup_start_button = self.ui.followup_start_button
followup_start_button.clicked.connect(threads.begin_initialize)
def followup_starting_number(self):
num = self.ui.lineEdit.text()
return num
def begin_initialize(self):
t1 = threading.Thread(target = followup.initialize, args = ())
t1.start()
threads = Threads()
if __name__ == '__main__':
app = QtWidgets.QApplication([])
widget = MainWindow()
widget.show()
app.exec_()
#followup.py
import workbot_main
def initialize():
row_number.number = workbot_main.MainWindow.followup_starting_number()
print(row_number.number)
I get this error
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\leamy\anaconda3\lib\threading.py", line 973, in _bootstrap_inner
self.run()
File "C:\Users\leamy\anaconda3\lib\threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\leamy\Desktop\work bot\followup.py", line 313, in initialize
row_number.number = workbot_main.MainWindow.followup_starting_number()
TypeError: followup_starting_number() missing 1 required positional argument: 'self'
I can't understand why it doesn't work.
Edit:
If I try to use
row_number.number = workbot_main.widget.followup_starting_number()
instead of
row_number.number = workbot_main.MainWindow.followup_starting_number()
I get this error
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\leamy\anaconda3\lib\threading.py", line 973, in _bootstrap_inner
self.run()
File "C:\Users\leamy\anaconda3\lib\threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\leamy\Desktop\work bot\followup.py", line 314, in initialize
row_number.number = workbot_main.widget.followup_starting_number()
AttributeError: module 'workbot_main' has no attribute 'widget'
I don't know if that is related.
Related
When running this code:
import tkinter as tk
class MyApplication(tk.Tk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.title('Programma')
self.geometry('500x400')
self.button = tk.Button(self, text='Execute', command=self.fun)
self.button.grid(row=0, column=4, stick=tk.W)
def fun(self):
print('Hello')
app = MyApplication()
app.mainloop()
I get the following error:
Traceback (most recent call last): File "C:/Users/Andrea/Desktop/hfhfhg.py", line 17, in <module>
app = MyApplication() File "C:/Users/Andrea/Desktop/hfhfhg.py", line 10, in __init__
self.button = tk.Button(self, text='Execute', command=self.fun) File "C:\WPy64-3910\python-3.9.1.amd64\lib\tkinter\__init__.py", line 2346, in __getattr__
return getattr(self.tk, attr) AttributeError: '_tkinter.tkapp' object has no attribute 'fun'
I understand that the code is not optimal for a GUI but I would like to understand how Tkinter works without using a frame object. Please can you help me?
I am learning multithreading in python. can anyone pleae tell me why the thread does not start?
code:
import threading
import time
import logging
class Threads_2:
def __new__(cls):
"""
this will be invoked once the creation procedure of the object begins
"""
instance = super(Threads_2,cls).__new__(cls)
return instance
def __init__(self):
"""
this will be invoked once the initialisation procedure of the object begins
"""
#self.configLogging()
#threadinf.Thread.__init__(self)
#self.spawnThreads()
def spawnThreads(self):
if __name__ == "__main__":
thread1 = threading.Thread(target=self.backgroundTask, args=(10,))
thread1.start()
def backgroundTask(numOfLoops):
for i in numOfLoops:
print(2)
obj = Threads_2()
obj.spawnThreads()
error:
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner
self.run()
File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\lib\threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
TypeError: backgroundTask() takes 1 positional argument but 2 were given
PS D:\python workspace>
The function backgroundTask is in the class Threads_2. So, it should be backgroundTask(self, numOfLoops) instead of backgroundTask(numOfLoops).
I am playing around with the Process library from multiprocessing and I was trying to call a class from another file as a separate process, however, I am getting this error:
Traceback (most recent call last):
File "/usr/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python3.6/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
TypeError: 'tuple' object is not callable
and it still exists in the same process as my stdout is this:
20472 __main__
20472 CALL
internal func call
Leaving Call
Process Process-1:
#This is where the error prints out
Leaving main
where 20472 is the pid.
Main File:
import CALL
from multiprocessing import Process
import os
if __name__ == '__main__':
print(os.getpid(),__name__)
p = Process(target=(CALL.Call(),))
p.start()
p.join()
print("Leaving main")
import os
Call Class File:
class Call():
def __init__(self):
print(os.getpid(), __name__)
self.internal()
def __exit__(self):
print("Leaving Call")
def internal(self):
print("internal func call")
self.__exit__()
As answered in the comments by #Jeronimo - changing
p = Process(target=(call.Call(),)
to
p = Process(target=(call.Call))
was the solution giving the correct output:
2965 __main__
2966 CALL
internal func call
Leaving Call
Leaving main
with a separate process for the called class.
E
======================================================================
ERROR: test_LoginCorrect (__main__.LoginCorrect)
----------------------------------------------------------------------
Traceback (most recent call last):
File "demo.py", line 12, in test_LoginCorrect
driver= webdriver.Remote(desired_capabilities=DesiredCapabilities().FIREFOX,command_executor='http://0.0.0.0:4444')
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 248, in
start_session
self.session_id = response['sessionId']
TypeError: string indices must be integers
----------------------------------------------------------------------
Ran 1 test in 20.878s
//Formatting is not properly done
FAILED (errors=1)
My test case file :
import unittest
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
class LoginCorrect(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Remote(command_executor='http://0.0.0.0:4444/wd/hub', desired_capabilities=DesiredCapabilities.FIREFOX)
def test_LoginCorrect(self):
user ="shubh"
pwd= "sha123#56su"
driver= webdriver.Remote(desired_capabilities=DesiredCapabilities().FIREFOX,command_executor='http://0.0.0.0:4444')
driver.get("http://0.0.0.0:8000/login")
elem = driver.find_element_by_id("id_username")
elem.send_keys(user)
elem = driver.find_element_by_id("id_password")
elem.send_keys(pwd)
driver.find_element_by_class_name('btn-block').click()
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest.main()
My machine has Linux 16.04LTS and selenium 3.3.0
Can somebody figure out this problem.
I'm build application with pyobject (gtk) in Pydev , but i'm try to create a window
the following way:
Class Ventana
from gi.overrides import Gtk
class Ventana( Gtk.Window ):
def __init__( self,titulo ):
Gtk.Window.__init__(self,title=titulo )
self.connect("delete-event",Gtk.main_quit )
Class Aplicacion( Main):
def main():
win = Ventana()
if __name__ == '__main__':
main()
but I'm try to compile te App, show the following mistake:
Traceback (most recent call last):
File "/home/demian/workspace/NidhugsRPG/nidhugs/presentacion/Consola.py", line 6, in
<module>
from gi.overrides import Gtk
File "/usr/lib/python3/dist-packages/gi/overrides/Gtk.py", line 35, in <module>
Gtk = modules['Gtk']._introspection_module
KeyError: 'Gtk'
I'm try use the import
from gi.repository import Gtk
but, not works,because moudule not found.So i'm use the import:
from gi.overrides import Gtk
¿How to fix my trouble?
Sorry for my bad English
Thanks.