Re: For a hierarchical project, the EXE file generated by "pyinstaller" does not start.
Chris Angelico schrieb am Dienstag, 7. Dezember 2021 um 19:16:54 UTC+1: > On Wed, Dec 8, 2021 at 4:49 AM Mohsen Owzar wrote: > > *** > > GPIOContrl.py > > *** > > class GPIOControl: > > def my_print(self, args): > > if print_allowed == 1: > > print(args) > > > > def __init__(self): > Can't much help with your main question as I don't do Windows, but one > small side point: Instead of having a my_print that checks if printing > is allowed, you can conditionally replace the print function itself. > > if not print_allowed: > def print(*args, **kwargs): pass > > ChrisA Thanks Chris Your answer didn't help me to solve my problem, but gave me another idea to write a conditional print statement. Regards Mohsen -- https://mail.python.org/mailman/listinfo/python-list
For a hierarchical project, the EXE file generated by "pyinstaller" does not start.
Hi all, I have a problem with "pyinstaller". When I compile a single Python file, an EXE file is created in the "dist" directory, with which I can start the program and the GUI appears after a few seconds. But when I try to compile my project with "pyinstaller Relais_LastDauerTester.py" and generate an EXE file from it, an ".exe" file is also created in the "dist" directory, but nothing happens when I run both .exe files from Windows Explorer with a double click or from the DOS shell by invoking it. The mouse pointer changes briefly to an hourglass and then back and nothing happens. The only difference between these two programs is that the first is just a single file and my project is structured hierarchically. I tried to demonstrate the structure of the project below with two "DIR" DOS commands. In PyCharm you only need to run the top file "Relais_LastDauerTester.py", so I used this file for "pyinstaller". But it looks like I have to give (I believe) an extra argument for a hierarchical project. I googled all weekend to find a workable solution. But all I found was for converting a ".py" file and not a project like mine. With some suggestions, I should add a "pause" or "input ()" command to the code to prevent the DOS shell from disappearing quickly, which is out of the question for me. Do you have any idea what it could be? I thank you in advance for any useful advice that could help me. Greeting Mohsen PS I work on a PC with 1201 INFO: PyInstaller: 4.7 1202 INFO: Python: 3.9.5 1282 INFO: Platform: Windows-10-10.0.18363-SP0 Project Structure from PyCharm &&& ...\SW\Relais_LastDauerTester_V0.5 &&& .idea Logfiles Relais_LastDauerTester 276 Relais_LastDauerTester.py Screenshotfiles 405 settings.ini &&& ...\SW\Relais_LastDauerTester_V0.5\Relais_LastDauerTester &&& 9’308 GPIOControl.py 90’618 GUI_View.py 998 main.py 28’625 TestControl.py 269 __init__.py __pycache__ Simplified project files with the "import" lines *** Relais_LastDauerTester.py.py *** #!/usr/bin/env python3 # -*- coding: utf-8 -*- from Relais_LastDauerTester.main import main if __name__ == "__main__": main() *** main.py *** import sys from PyQt5.QtCore import * from PyQt5.QtWidgets import QApplication from .GUI_View import MainWindow def main(): app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_()) if __name__ == '__main__': main() *** GUI_View.py *** import sys import subprocess import PyQt5.QtGui as qtg from PyQt5.QtWidgets import (QLabel, QPushButton, QLineEdit, QCheckBox, QWidget, QVBoxLayout, QHBoxLayout, QGridLayout, QDialog, QFileDialog) from .TestControl import * class MainWindow(QWidget): def __init__(self): super().__init__() def createMainWindow(self): ... def exitMainWindow(self): ... def ChangeToPrefWindow(self): self.prefwindow.show() self.hide() class PrefWindow(QWidget): def __init__(self, parent=None): super().__init__() self.parent = parent ... self.createPrefWindow() def ChangeToMainWindow(self): ... def createPrefWindow(self): ... class CustomLineEdit(QLineEdit): clicked = pyqtSignal() def mousePressEvent(self, QMouseEvent): self.clicked.emit() class Keypad_Window_New(QDialog): def __init__(self, num=0, parent=None): super().__init__(parent) self.parent = parent ... TestContrl.py *** from PyQt5.QtCore import * from .GPIOControl import GPIOControl class WorkerSignals(QObject): signal_Update_Label = pyqtSignal() class TestControl(QRunnable): signals = WorkerSignals() def __init__(self, parent=None): super().__init__() self.parent = parent ... *** GPIOContrl.py *** class GPIOControl: def my_print(self, args): if print_allowed == 1: print(args) def __init__(self): -- https://mail.python.org/mailman/listinfo/python-list
New overriden and generated QLineEdit class will not be placed on the MainWindow as expected
Hi all Some days ago, I send a question to this community about a clickable QLineEdit. After getting the Hint to use QMouseEvent, I've written the program which is working almost good but with a small or perhaps big ugliness and that is: Below is the imgur link to the screenshots of my program after clicking the buttons in sequence: https://imgur.com/a/rfcP3qB As you will see in the code blow, I override the QlineEdit widget and define a new class " CustomLineEdit " to generate a "clicked" signal, when the user pressed with mouse on this field. I use this "CustomLineEdit" class and place it on the MainWindow with the desired "layout". I couldn't figure out, why this widget is placed not in the MainWindow, but outside this window, as you can see in the top picture of the attached screenshots. When I take the line 12 (self.show()) from the code, the generated class will not appear. The problem here is that at the beginning, the MainWindow with a LineEdit field should appear at the program start. Then, after clicking on this field, the keypad should come up outside the MainWindow. Could anyone see, where my mistake is? Thanks for any help. Mohsen Here is the code: &&& import sys from PyQt5.QtWidgets import (QApplication, QLineEdit, QPushButton, QMainWindow, QVBoxLayout, QHBoxLayout, QGridLayout, QWidget) from PyQt5.QtCore import pyqtSignal, pyqtSlot class CustomLineEdit(QLineEdit): clicked = pyqtSignal() def __init__(self): super().__init__() self.show() def mousePressEvent(self, QMouseEvent): self.clicked.emit() class MainWindow(QMainWindow): def __init__( self, parent=None ): super().__init__(parent) self.title = 'Window 1' self.left = 700 self.top = 300 self.width = 200 self.height = 200 self.initUI() def initUI(self): self.keypad_window = Keypad_Window(self) hbox = QHBoxLayout() self.cle = CustomLineEdit() self.cle.clicked.connect(self.show_keypad_window) self.cle.setFixedSize(220, 60) self.cle.setStyleSheet("color: red;" "background-color: yellow;" "font-family: Arial;" "font-weight: Bold;" "font-size: 30pt") hbox.addWidget(self.cle) self.setLayout(hbox) self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.show() def show_keypad_window(self): self.keypad_window.show() self.hide() def close(self): self.keypad_window.close() super(MainWindow, self).close() @pyqtSlot(str) def update_label(self, txt): self.cle.setText(txt) class Keypad_Window(QWidget): def __init__(self, parent=None): super().__init__() self.parent = parent self.setGeometry(1200, 500, 230, 400) vbox = QVBoxLayout() self.display = QLineEdit() self.display.setFixedSize(220, 60) self.display.setReadOnly(True) self.display.setStyleSheet("color: Blue; " "background-color: lightgreen;" "font-family: Arial;" "font-weight: Bold;" "font-size: 18pt") vbox.addWidget(self.display) """Create the buttons.""" self.buttons = {} self.gridlay = QGridLayout() self.button_name = [['7', '8', '9'], ['4', '5', '6'], ['1', '2', '3'], ['C', '0', '>']] self.command_name = [['7', '8', '9'], ['4', '5', '6'], ['1', '2', '3'], ['delete', '0', 'accept']] for i in range(4): for j in range(3): text = self.button_name[i][j] # keep a reference to the buttons self.buttons[i, j] = QPushButton() self.buttons[i, j].setText(text) self.buttons[i, j].setObjectName(text) self.buttons[i, j].setFixedSize(70, 70) if i == 3: if j == 0: self.buttons[i, j].setToolTip('Each click deletes\na digit to the left') if j == 2: self.buttons[i, j].setToolTip('The whole displayed\nvalue will be taken!') self.buttons[i, j].clicked.connect(self.call_button_fun(i, j, self.command_name)) # add to the GridLayout self.gridlay.addWidget(self.buttons[i, j], i, j) self.buttons[i, j].setStyleSheet("color: blue; " "background-color: cyan;"
Open a new window by mouse clicking in the QLineEdit field and not by clicking of a button
Hi all, I'm looking for an approach, but couldn't find any appropriate answer to my problem: On my GUI on a tablet, I have bunch of QlineEdit widgets for the settings of my task. Because we have no keyboard connected to the tablet, I have put two buttons ("+" and "-") around each QLineEdit widget to increase or decrease its value. When the target value is far away from the displayed one in the QLineEdit, I have to click lots of times to reach the end value. Due to this ugliness feature, I wanted to offer to the user the possibility to click in the edit field to get another window with a numeric keypad to type the target value. And then by clicking an OK button, the new window will be closed and the typed value will be taken into the QLineEdit widget of my original GUI. In all my searches, I found examples to open new windows by clicking a button and not by clicking in an edit field. I used the following line to have an edit field on window1. self.text_from_window2 = QLineEdit('Setting Value') And wanted to open another window (window2) in which I programmed a numeric keypad. By typing the desired value on this keypad and enter OK, this value should be taken to the edit field of window1. But the following line brings an error that QLineEdit has no attribute "clicked". self.text_from_window2.clicked().connect(self.show_keypad_window) I tried to use other attributes like focus, textChanged or textEdited. None of them could help me. Is it at all possible to use QLineEdit with mouse click to generate an action (open new window)? Has anyone an example of such a code snippet? I am very curious to see if someone has a solution to my problem. Regards Mohsen -- https://mail.python.org/mailman/listinfo/python-list
Re: Free OCR package in Python and selecting appropriate widget for the GUI
Mohsen Owzar schrieb am Donnerstag, 23. September 2021 um 08:53:15 UTC+2: > DFS schrieb am Mittwoch, 22. September 2021 um 09:41:42 UTC+2: > > On 9/22/2021 1:54 AM, Mohsen Owzar wrote: > > > DFS schrieb am Mittwoch, 22. September 2021 um 05:10:30 UTC+2: > > >> On 9/21/2021 10:38 PM, Mohsen Owzar wrote: > > >>> DFS schrieb am Dienstag, 21. September 2021 um 15:45:38 UTC+2: > > >>>> On 9/21/2021 4:36 AM, Mohsen Owzar wrote: > > >>>>> Hi Guys > > >>>>> Long time ago I've written a program in Malab a GUI for solving > > >>>>> Sudoku puzzles, which worked not so bad. > > >>>>> Now I try to write this GUI with Python with PyQt5 or TKinter. > > >>>>> First question is: > > >>>>> Is there any free OCR software, packages or code in Python, which I > > >>>>> can use to recognize the given digits and their positions in the > > >>>>> puzzle square. > > >>>>> Second: > > >>>>> Because, I can not attach a picture to this post, I try to describe > > >>>>> my picture of my GUI. > > >>>> Draw your GUI in PyQt designer or other graphics tool, then upload a > > >>>> screenshot of it to imgur, then post the link to the picture. > > >>> Thanks, for your answer. Hi > > >>> But, what is "imgur"? > > >>> I'm not so familiar with handling of pictures in this group. > > >>> How can I call "imgur" or how can I get there? > > >>> > > >>> Regards > > >>> Mohsen > > >> www.imgur.com > > >> > > >> It's a website you can upload image files or screenshots to. Then you > > >> can copy a link to your picture and post the link here. > > > I have already posted the link, but I can not see it anywhere. > > > Now, I post it again: > > > https://imgur.com/a/Vh8P2TE > > > I hope that you can see my two images. > > > Regards > > > Mohsen > > Got it. > > > > I haven't used tkinter. In PyQt5 designer I think you should use one > > QTextEdit control for each square. > > > > > > Each square with the small black font can be initially populated with > > > > 1 2 3 > > 4 5 6 > > 7 8 9 > > > > > > > > https://imgur.com/lTcEiML > > > > > > > > some starter python code (maybe save as sudoku.py) > > > > = > > from PyQt5 import Qt, QtCore, QtGui, QtWidgets, uic > > from PyQt5.Qt import * > > from PyQt5.QtCore import * > > from PyQt5.QtGui import * > > from PyQt5.QtWidgets import * > > > > #objects > > app = QtWidgets.QApplication([]) > > frm = uic.loadUi("sudoku.ui") > > > > > > #grid = a collection of squares > > grids = 1 > > > > #squares = number of squares per grid > > squares = 9 > > > > #fill the squares with 1-9 > > def populateSquares(): > > for i in range(grids,grids+1): > > for j in range(1,squares+1): > > widget = frm.findChild(QtWidgets.QTextEdit, "txt{}_{}".format(i,j)) > > widget.setText("1 2 3 4 5 6 7 8 9") > > > > #read data from squares > > def readSquares(): > > for i in range(grids,grids+1): > > for j in range(1,squares+1): > > print("txt%d_%d contains: %s" % > > (i,j,frm.findChild(QtWidgets.QTextEdit, > > "txt{}_{}".format(i,j)).toPlainText())) > > > > > > #connect pushbuttons to code > > frm.btnPopulate.clicked.connect(populateSquares) > > frm.btnReadContents.clicked.connect(readSquares) > > > > #show main form > > frm.show() > > > > #initiate application > > app.exec() > > = > > > > > > > > > > > > .ui file (ie save as sudoku.ui) > > = > > > > > > > > MainWindow > > > > > > > > 0 > > 0 > > 325 > > 288 > > > > > > > > Sudoku > > > > > > > > > > > > 32 > > 22 > > 83 > > 65 > > > > > > > > > > Cou
Re: Flush / update GUIs in PyQt5 during debugging in PyCharm
DFS schrieb am Freitag, 24. September 2021 um 14:52:41 UTC+2: > On 9/24/2021 12:46 AM, Mohsen Owzar wrote: > > Hi Guys > > I've written a GUI using PyQt5 and in there I use StyleSheets (css) for the > > buttons and labels to change their background- and foreground-colors and > > their states as well. > > Because my program doesn't function correctly, I try to debug it in my IDE > > (PyCharm). > > The problem is that during debugging, when I change some attributes of a > > button or label, let say its background-color, I can not see this > > modification of the color until the whole method or function is completed. > > I believe that I have seen somewhere during my searches and googling that > > one can flush or update the GUI after each step/action is done. > > But until now I couldn't manage it and I don't know where I have to invoke > > flush/update command in PyCharm. > > If anyone has done this before and knows about it, I would very appreciate > > seeing his solution. > > > > Regards > > Mohsen > screen: > form.repaint() > > individual widgets: > form.widget.repaint() @DFS Hi I tried to use your suggestion in my code, to see changes in the background-color of the widgets (buttons and labels). Below is the link of two screenshots of my GUI: https://imgur.com/a/5LIefN7 They show the start phase and after clicking the “All Active” button. As I wrote before, I use Stylesheets for configuring widgets. Here is the code snipped of the relevant part: :: if state == 'All Active': . . . . . . for i in range(7): for j in range(6): self.buttons_active[j].setText('Inactive') self.buttons_active[j].setEnabled(True) self.buttons_active[j].setChecked(True) self.buttons_active[j].setStyleSheet(css_pushButton()) ## self.buttons_reset[j].setChecked(True) self.buttons_reset[j].setEnabled(False) self.buttons_reset[j].setStyleSheet(css_pushButton()) # if i > 0 and j < 6: self.labels[i, j].setProperty('orange', True) # self.labels[i, j].repaint() # = 4 else: self.labels[i, j].setProperty('yellow', True) # self.labels[i, j].repaint() # = 4 self.labels[i, j].setStyleSheet(css_Label()) self.labels[i, j].repaint() aaa = 4 # else: . . . . . . for i in range(7): for j in range(6): self.buttons_active[j].setText('Active') self.buttons_active[j].setEnabled(True) self.buttons_active[j].setStyleSheet(css_pushButton()) ## ## self.buttons_reset[j].setChecked(False) self.buttons_reset[j].setEnabled(True) self.buttons_reset[j].setStyleSheet(css_pushButton()) ## if i > 0: ## self.labels[i, j].setProperty('gray', True) # self.labels[i, j].repaint() # = 4 else: self.labels[i, j].setProperty('yellow', True) # self.labels[i, j].repaint() # = 4 self.labels[i, j].setStyleSheet(css_Label()) self.labels[i, j].repaint() aaa = 4 :: As you can see, the if-else part has to change the background-color of the gray labels (at the start) and the buttons “Active”, “Reset”, “All Active” and “Exit” to orange. The problem is, after clicking on the “All Active” button all “Resets” and the gray labels change their background-color to orange as desired. But when I afterwards click again on this button (Now its name is “All In
Flush / update GUIs in PyQt5 during debugging in PyCharm
Hi Guys I've written a GUI using PyQt5 and in there I use StyleSheets (css) for the buttons and labels to change their background- and foreground-colors and their states as well. Because my program doesn't function correctly, I try to debug it in my IDE (PyCharm). The problem is that during debugging, when I change some attributes of a button or label, let say its background-color, I can not see this modification of the color until the whole method or function is completed. I believe that I have seen somewhere during my searches and googling that one can flush or update the GUI after each step/action is done. But until now I couldn't manage it and I don't know where I have to invoke flush/update command in PyCharm. If anyone has done this before and knows about it, I would very appreciate seeing his solution. Regards Mohsen -- https://mail.python.org/mailman/listinfo/python-list
When should I use "parent=None" in __ini__ and "parent" in super()
Hi Guys I'm writing since almost one-year codes in Python, using TKinter and PyQt5. I'm somehow able to writes GUIs in both of them. But since I'm using more Pyqt5 and using classes with initialization and super() constructs, and also I saw lots of videos and examples of coding them, I still don’t know exactly how and when should I use the parent in __init()__ and super() construct. For example, the following lines use "parent=None" in the __init__ construct and "parent" in the super() construct. And sometimes I do not see any of them in these two constructs. class MyClass1(QWidget): def __init__(self, name, parent=None): super(MyClass1, self).__init__(parent) print(self.parent().test) And sometimes without "parent" like the following: class MyClass2(QWidget): def __init__(self, name): super(MyClass2, self).__init__() print(self.parent().test) Could anyone explain this to me when and for which action I have to use the first one "MyClass1" and when the second one "MyClass2"? Regards Mohsen -- https://mail.python.org/mailman/listinfo/python-list
Re: Free OCR package in Python and selecting appropriate widget for the GUI
DFS schrieb am Mittwoch, 22. September 2021 um 09:41:42 UTC+2: > On 9/22/2021 1:54 AM, Mohsen Owzar wrote: > > DFS schrieb am Mittwoch, 22. September 2021 um 05:10:30 UTC+2: > >> On 9/21/2021 10:38 PM, Mohsen Owzar wrote: > >>> DFS schrieb am Dienstag, 21. September 2021 um 15:45:38 UTC+2: > >>>> On 9/21/2021 4:36 AM, Mohsen Owzar wrote: > >>>>> Hi Guys > >>>>> Long time ago I've written a program in Malab a GUI for solving Sudoku > >>>>> puzzles, which worked not so bad. > >>>>> Now I try to write this GUI with Python with PyQt5 or TKinter. > >>>>> First question is: > >>>>> Is there any free OCR software, packages or code in Python, which I can > >>>>> use to recognize the given digits and their positions in the puzzle > >>>>> square. > >>>>> Second: > >>>>> Because, I can not attach a picture to this post, I try to describe my > >>>>> picture of my GUI. > >>>> Draw your GUI in PyQt designer or other graphics tool, then upload a > >>>> screenshot of it to imgur, then post the link to the picture. > >>> Thanks, for your answer. > >>> But, what is "imgur"? > >>> I'm not so familiar with handling of pictures in this group. > >>> How can I call "imgur" or how can I get there? > >>> > >>> Regards > >>> Mohsen > >> www.imgur.com > >> > >> It's a website you can upload image files or screenshots to. Then you > >> can copy a link to your picture and post the link here. > > I have already posted the link, but I can not see it anywhere. > > Now, I post it again: > > https://imgur.com/a/Vh8P2TE > > I hope that you can see my two images. > > Regards > > Mohsen > Got it. > > I haven't used tkinter. In PyQt5 designer I think you should use one > QTextEdit control for each square. > > > Each square with the small black font can be initially populated with > > 1 2 3 > 4 5 6 > 7 8 9 > > > > https://imgur.com/lTcEiML > > > > some starter python code (maybe save as sudoku.py) > > = > from PyQt5 import Qt, QtCore, QtGui, QtWidgets, uic > from PyQt5.Qt import * > from PyQt5.QtCore import * > from PyQt5.QtGui import * > from PyQt5.QtWidgets import * > > #objects > app = QtWidgets.QApplication([]) > frm = uic.loadUi("sudoku.ui") > > > #grid = a collection of squares > grids = 1 > > #squares = number of squares per grid > squares = 9 > > #fill the squares with 1-9 > def populateSquares(): > for i in range(grids,grids+1): > for j in range(1,squares+1): > widget = frm.findChild(QtWidgets.QTextEdit, "txt{}_{}".format(i,j)) > widget.setText("1 2 3 4 5 6 7 8 9") > > #read data from squares > def readSquares(): > for i in range(grids,grids+1): > for j in range(1,squares+1): > print("txt%d_%d contains: %s" % > (i,j,frm.findChild(QtWidgets.QTextEdit, > "txt{}_{}".format(i,j)).toPlainText())) > > > #connect pushbuttons to code > frm.btnPopulate.clicked.connect(populateSquares) > frm.btnReadContents.clicked.connect(readSquares) > > #show main form > frm.show() > > #initiate application > app.exec() > = > > > > > > .ui file (ie save as sudoku.ui) > = > > > > MainWindow > > > > 0 > 0 > 325 > 288 > > > > Sudoku > > > > > > 32 > 22 > 83 > 65 > > > > > Courier > 12 > 50 > false > > > > false > > > color: rgb(0, 0, 127); > background-color: rgb(255, 255, 127); > > > QFrame::StyledPanel > > > QFrame::Sunken > > > Qt::ScrollBarAlwaysOff > > > true > > > > > > 114 > 22 > 83 > 65 > > > > > Courier > 12 > 50 > false > > > > false > > > color: rgb(0, 0, 127); > background-color: rgb(255, 255, 127); > > > QFrame::StyledPanel > > > QFrame::Sunken > > > Qt::ScrollBarAlwaysOff > > > true > > > > > > 196 > 22
Re: Free OCR package in Python and selecting appropriate widget for the GUI
DFS schrieb am Mittwoch, 22. September 2021 um 05:10:30 UTC+2: > On 9/21/2021 10:38 PM, Mohsen Owzar wrote: > > DFS schrieb am Dienstag, 21. September 2021 um 15:45:38 UTC+2: > >> On 9/21/2021 4:36 AM, Mohsen Owzar wrote: > >>> Hi Guys > >>> Long time ago I've written a program in Malab a GUI for solving Sudoku > >>> puzzles, which worked not so bad. > >>> Now I try to write this GUI with Python with PyQt5 or TKinter. > >>> First question is: > >>> Is there any free OCR software, packages or code in Python, which I can > >>> use to recognize the given digits and their positions in the puzzle > >>> square. > >>> Second: > >>> Because, I can not attach a picture to this post, I try to describe my > >>> picture of my GUI. > >> Draw your GUI in PyQt designer or other graphics tool, then upload a > >> screenshot of it to imgur, then post the link to the picture. > > Thanks, for your answer. > > But, what is "imgur"? > > I'm not so familiar with handling of pictures in this group. > > How can I call "imgur" or how can I get there? > > > > Regards > > Mohsen > www.imgur.com > > It's a website you can upload image files or screenshots to. Then you > can copy a link to your picture and post the link here. I have already posted the link, but I can not see it anywhere. Now, I post it again: https://imgur.com/a/Vh8P2TE I hope that you can see my two images. Regards Mohsen -- https://mail.python.org/mailman/listinfo/python-list
Re: Free OCR package in Python and selecting appropriate widget for the GUI
DFS schrieb am Dienstag, 21. September 2021 um 15:45:38 UTC+2: > On 9/21/2021 4:36 AM, Mohsen Owzar wrote: > > Hi Guys > > Long time ago I've written a program in Malab a GUI for solving Sudoku > > puzzles, which worked not so bad. > > Now I try to write this GUI with Python with PyQt5 or TKinter. > > First question is: > > Is there any free OCR software, packages or code in Python, which I can use > > to recognize the given digits and their positions in the puzzle square. > > Second: > > Because, I can not attach a picture to this post, I try to describe my > > picture of my GUI. > Draw your GUI in PyQt designer or other graphics tool, then upload a > screenshot of it to imgur, then post the link to the picture. Thanks, for your answer. But, what is "imgur"? I'm not so familiar with handling of pictures in this group. How can I call "imgur" or how can I get there? Regards Mohsen -- https://mail.python.org/mailman/listinfo/python-list
Free OCR package in Python and selecting appropriate widget for the GUI
Hi Guys Long time ago I've written a program in Malab a GUI for solving Sudoku puzzles, which worked not so bad. Now I try to write this GUI with Python with PyQt5 or TKinter. First question is: Is there any free OCR software, packages or code in Python, which I can use to recognize the given digits and their positions in the puzzle square. Second: Because, I can not attach a picture to this post, I try to describe my picture of my GUI. It is a 3x3 block / matrix (one third of the whole Sudoku 9x9 block). This block must be placed three times in row and columns. Each square of this 3x3 block has 3x3 digits from 1 to 9 at the initialization time. These digits are spread out in 3x3 equal distances. These are small fonts and black. The values given by the puzzle are red big fonts and not changeable The digits typed by the user are black big fonts and changeable If there is a big font from the Puzzle / User, these must be removed from the neighboring fields from the 3x3 matrix (1-9). Now my question is, actually a hint from your side: What should I take as widget for one of these small squares to have different content as I described above? I thought of a QLineEdit in PyQt5 or LineEdit in TKinter, because the user must type some values in there and therefore can not be labels. So again, for the sake of the clarity. • When the fields are empty, each square has to show digits from 1 to 9 with small fonts in 3x3 matrix order. • Given values in the puzzle are big fonts and red. • Digits which are typed by the user are big fonts and black. Now the question is, can I take only one LineEdit for all these tree situations, or I have to implement 9 small squares for small fonts and a big one for the big fonts? Any help and suggestion is welcome and appreciated. Best regards Mohsen -- https://mail.python.org/mailman/listinfo/python-list
Re: PyQt5 is not recognized from python 3.8 installation in python 3.10
Barry schrieb am Dienstag, 24. August 2021 um 00:25:38 UTC+2: > > On 23 Aug 2021, at 00:00, Mats Wichmann wrote: > > > > On 8/22/21 7:04 AM, Mohsen Owzar wrote: > >> Hi guys, > >> I have on my laptop the python installation 3.8 and newly I installed > >> newest version 3.10 as well on my laptop. > >> Now I have two IDLEs for both of the installations. > >> When I rund some *.py file, having PyQt5 module, on the 3.8 version, it > >> works as before without any problems. > >> But whenn I run the same file on IDLE with 3.10 installation, it crashes > >> and says that PyQt5 is not known. > >> I tried to install this package with"pip install pyqt5" or with "py -3 -m > >> pip install pyqt5", it brings lots of error messages (long long) as the > >> lines below (they are only the beginning of the messages): > > > > make sure you're getting the right Python by doing > > > > py -3.10 -m pip install pyqt5 > > > > (the fact you're getting the build error below indicates you _are_ getting > > the right one, but it's good to be explicit anyway, just so you're sure). > > > >> == > >> C:\Users\Mohsen>py -3 -m pip install pyqt5 > >> Collecting pyqt5 > >> Using cached PyQt5-5.15.4.tar.gz (3.3 MB) > >> Installing build dependencies ... done > >> Getting requirements to build wheel ... done > >> Preparing wheel metadata ... error > >> ERROR: Command errored out with exit status 1: > >> command: > >> 'C:\Users\Mohsen\AppData\Local\Programs\Python\Python310\python.exe' > >> 'C:\Users\Mohsen\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py' > >> prepare_metadata_for_build_wheel > >> 'C:\Users\Mohsen\AppData\Local\Temp\tmprax0esmt' > >> cwd: > >> C:\Users\Mohsen\AppData\Local\Temp\pip-install-wl_b58e9\pyqt5_1cbd1bab46fa4abaad34b55514561ce6 > >> > >> Complete output (33 lines): > >> Querying qmake about your Qt installation... > >> C:\Qt\4.7.4\bin\qmake.exe -query > >> Traceback (most recent call last): > >> File > >> "C:\Users\Mohsen\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", > >> line 143, in prepare_metadata_for_build_wheel > >> hook = backend.prepare_metadata_for_build_wheel > >> AttributeError: module 'sipbuild.api' has no attribute > >> 'prepare_metadata_for_build_wheel' > > > > Your problem here is that there's no released binary wheel for PyQt5, since > > Py 3.10 isn't released (there's been some recent chatter about encouraging > > projects to make builds for new Python versions available early, e.g. once > > a Python version hits release candidate state, but that's just that - > > chatter - for now). > > > > In theory your system should be able to build it, but my experience is that > > unless you're an active Python developer on Windows and already have the > > right working setup, it pretty much always fails. These are the perils of > > trying to use a pre-release... > > > > That error suggests there's something different going on than usual (which > > has to do with the MSVC compiler suite not being set up the way the package > > expects): there looks like a version mismatch - it looks like it's finding > > qmake for Qt4, not Qt5. Maybe you can make some progress by adjusting some > > paths? > Only trivial C code extensions can be built on windows. > And then only if you have the right MSVC tools installed. > Most interesting extensions have dependencies only other software. > Which means that you need to know how to build all the dependencies as well. > > For something as complex as PyQt5 you need to be a developer with reasonable > experience to build it. > > Check on PyPI for the available versions and install one of them. > > Barry > > > > Many people go here to get early-access, albeit unofficial, binary wheels: > > > > https://www.lfd.uci.edu/~gohlke/pythonlibs > > > > Unfortunately, PyQt5 is not available from there (as listed in the section > > at the very bottom) > > > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Thanks a lot for your answers. That's true. I had a project which used Qt4.7, and I have still on my laptop. I have not so big knowledge about compiling and building stuff, so I have to get rid of 3.10 version. OK, then I try to remove Python 3.10 and to install 3.9.6. Best regards Mohsen -- https://mail.python.org/mailman/listinfo/python-list
PyQt5 is not recognized from python 3.8 installation in python 3.10
Hi guys, I have on my laptop the python installation 3.8 and newly I installed newest version 3.10 as well on my laptop. Now I have two IDLEs for both of the installations. When I rund some *.py file, having PyQt5 module, on the 3.8 version, it works as before without any problems. But whenn I run the same file on IDLE with 3.10 installation, it crashes and says that PyQt5 is not known. I tried to install this package with"pip install pyqt5" or with "py -3 -m pip install pyqt5", it brings lots of error messages (long long) as the lines below (they are only the beginning of the messages): == C:\Users\Mohsen>py -3 -m pip install pyqt5 Collecting pyqt5 Using cached PyQt5-5.15.4.tar.gz (3.3 MB) Installing build dependencies ... done Getting requirements to build wheel ... done Preparing wheel metadata ... error ERROR: Command errored out with exit status 1: command: 'C:\Users\Mohsen\AppData\Local\Programs\Python\Python310\python.exe' 'C:\Users\Mohsen\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\Mohsen\AppData\Local\Temp\tmprax0esmt' cwd: C:\Users\Mohsen\AppData\Local\Temp\pip-install-wl_b58e9\pyqt5_1cbd1bab46fa4abaad34b55514561ce6 Complete output (33 lines): Querying qmake about your Qt installation... C:\Qt\4.7.4\bin\qmake.exe -query Traceback (most recent call last): File "C:\Users\Mohsen\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 143, in prepare_metadata_for_build_wheel hook = backend.prepare_metadata_for_build_wheel AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\Mohsen\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 349, in main() File "C:\Users\Mohsen\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 331, in main json_out['return_val'] = hook(**hook_input['kwargs']) == It begins with "PyQt5-5.15.4.tar.gz" and goes down "PyQt5-5.15.3.tar.gz" and so on, after it cannot install that version. After it reaches the "PyQt5-5.14.0.tar.gz" it breaks the downloading and bring this message == WARNING: Discarding https://files.pythonhosted.org/packages/3a/fb/eb51731f2dc7c22d8e1a63ba88fb702727b324c6352183a32f27f73b8116/PyQt5-5.14.1.tar.gz#sha256=2f230f2dbd767099de7a0cb915abdf0cbc3256a0b5bb910eb09b99117db7a65b (from https://pypi.org/simple/pyqt5/) (requires-python:>=3.5). Command errored out with exit status 1: 'C:\Users\Mohsen\AppData\Local\Programs\Python\Python310\python.exe' 'C:\Users\Mohsen\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\Mohsen\AppData\Local\Temp\tmp6t_i9jm7' Check the logs for full command output. Downloading PyQt5-5.14.0.tar.gz (3.2 MB) || 3.2 MB 3.3 MB/s ERROR: pyqt5 from https://files.pythonhosted.org/packages/7c/5b/e760ec4f868cb77cee45b4554bf15d3fe6972176e89c4e3faac941213694/PyQt5-5.14.0.tar.gz#sha256=0145a6b7de15756366decb736c349a0cb510d706c83fda5b8cd9e0557bc1da72 has a pyproject.toml file that does not comply with PEP 518: 'build-system.requires' contains an invalid requirement: 'sip >=5.0.1 <6' == What is wrong with my installations. How can I get all the packages available in 3.8 version also available for 3.10 version without any new installation in 3.10 for each all already existing packages? Thanks a lot in advance for you contributions. Mohsen -- https://mail.python.org/mailman/listinfo/python-list
Re: How to access a variable from one tab in another tab of a notebook?
Alan Gauld schrieb am Donnerstag, 8. April 2021 um 15:40:19 UTC+2: > On 08/04/2021 06:01, Mohsen Owzar wrote: > > >> But this is why GUIs are often(usually?) built as a class > >> because you can store all the state variables within > >> the instance and access them from all the methods. > >> > >> You can do it with functions but you usually wind up > >> with way too many globals to be comfortable. > > Because I'm a newbie in Python and write programs since > > a couple of months, and I'm not so familiar with classes, > OK, In that case you should probably read up on classes > and play around with them to get used to the ideas of > classes, objects and methods. > > You can carry on using functions but you will need to > keep track of quite a lot of global variables which > can get messy in bigger programs. Classes just keep > things a bit more tidy. > > would be very nice to give me a code, how I have to > > change my code into a class form. > > I tried without a class and I ran into problems that > > the defined frame and entry are not defined. > One of the problems in your code is that you are not > storing references to the widgets you create. You are > relying on the containment tree to store the references > and keep them alive. But that makes it difficult to > access. As a general rule of thumb if you are creating > any widget that responds to events you should keep > a reference to it - ie. create a variable. > > For example in your code you have a section like this: > > def gen_t2(frame): > def getValue(event):... > lbl = Label(frame, text='Val').pack() > > ent = Entry(frame) > ent.pack() > ent.insert(0, '2') > > ent.bind('', getValue) > And you call it like this: > > if firstTime2 == 1: if firstTime2 == 1: > gen_t2(tab2) > firstTime2 = 0 > > gen_t2(tab2) > firstTime2 = 0 > > Inside the function you store a reference to the Entry as ent. > but ent disappears as soon as the function ends, you cannot > use ent to access your entry outside the function. > You need to return the widget like so: > > def gen_t2(frame): > def getValue(event):... > > ... > ent.bind('', getValue) > return ent > > And then call it like: > > if firstTime2: > entry_field = gen_t2(tab2) > firstTime2 = False > > Now you can access your Entry field via the global > variable entry_field. > > I suspect you should forget about the classes for now, focus > on getting the functions to work, especially returning values > and storing those in global variables that you can access from > elsewhere. These principles are just as important when you > get round to studying classes later. > > And remember that global variables in one module can be > accessed from another module by importing the first module > into the second and using the module name as prefix. > > import tab2 > > txt = tab2.entry_field.get() > > HTH > > You might also find the functions, namespaces and GUI sections > of my tutorial useful (see below). > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos Hello Alan, I'm so happy that you have so good explained to me, what I have to do. Now, it is a bit clearer how I can use the variables or references in another modules. I try to follow your suggestions to see if I can solve my problem. Again thank you very much. Best regards Mohsen -- https://mail.python.org/mailman/listinfo/python-list
Re: How to access a variable from one tab in another tab of a notebook?
Alan Gauld schrieb am Donnerstag, 8. April 2021 um 02:05:01 UTC+2: > On 07/04/2021 09:35, Mohsen Owzar wrote: > > > The problem is that I can't use the variable "val" from Tab2 in Tab 1, > > # Filename: Tab1.py > > from tkinter import * > > > > def gen_t1(frame): > > f = LabelFrame(frame, text='f', bg='lightgreen') > > f.pack(expand=True, fill='both') > > > > b1 = Button(f, text='B1').pack() > > > > ## if val > 5: > > # Filename: Tab2.py > > from tkinter import * > > > > def gen_t2(frame): > > def getValue(event): > > val = ent.get() > > print(val) > Note that val is a local variable within a nested function. > It only exists while the nested function is executing. > As soon as the function ends val is thrown away. > > If you want the value of the entry you need to store it > in a variable that is visible after the function exits > (by returning it perhaps? or setting a global - ugly) > > But you still have the problem of making that visible > to Tab1. You could import tab2 into tab1 and use Tab2.varName > > But this is why GUIs are often(usually?) built as a class > because you can store all the state variables within > the instance and access them from all the methods. > > You can do it with functions but you usually wind up > with way too many globals to be comfortable. > > from Tab1 import gen_t1 > > from Tab2 import gen_t2 > ... > > def on_tab_change(event): > > global firstTime1, firstTime2 > > > > tab = event.widget.tab('current','text') > > if tab == 'Tab 1': > > print('Tab 1') > > if firstTime1 == 1: > > gen_t1(tab1) > > firstTime1 = 0 > Probably nicer to use boolean values for > firstTime1 and firstTime2, ie True and False > rather than their numeric equivalents. > > HTH > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos Hi Alan G, Thanks a lot for giving me this solution. Because I'm a newbie in Python and write programs since a couple of months, and I'm not so familiar with classes, would be very nice to give me a code, how I have to change my code into a class form. I tried without a class and I ran into problems that the defined frame and entry are not defined. Best regards Mohsen -- https://mail.python.org/mailman/listinfo/python-list
How to access a variable from one tab in another tab of a notebook?
Hi guys I have written a GUI with two tabs, Tab 1 and Tab 2 as shown below: On Tab 2 should be my settings parameters placed like "Val". If the user types a value greater than 5 in the entry field, the background color of Tab1 should be changed from light green to gray and the button "B1" should be disabled The problem is that I can't use the variable "val" from Tab2 in Tab 1, even if I have defined in every function and file as the global. It brought all the times the error message "val is not defined in Tab 1". You can run the top level "TabTop" to see my GUIs and uncomment the if part in Tab1 to see the error message. Any help is really appreciated Regards Mohsen # Filename: Tab1.py from tkinter import * def gen_t1(frame): f = LabelFrame(frame, text='f', bg='lightgreen') f.pack(expand=True, fill='both') b1 = Button(f, text='B1').pack() ## if val > 5: ##f_enabled = 'disabled' ##f['bg'] = 'lightgray' ## else: ##f_enabled = 'normal' ##f['bg'] = 'lightgreen' ## # Filename: Tab2.py from tkinter import * def gen_t2(frame): def getValue(event): val = ent.get() print(val) lbl = Label(frame, text='Val').pack() ent = Entry(frame) ent.pack() ent.insert(0, '2') ent.bind('', getValue) The code for the top level is: ## # Filename: TabTop from tkinter import * from tkinter import ttk from Tab1 import gen_t1 from Tab2 import gen_t2 global nb firstTime1 = 1 firstTime2 = 1 root = Tk() root.title('Tab-Tester') root.geometry('300x200') nb = ttk.Notebook(root) tab1 = Frame(nb) tab2 = Frame(nb) nb.add(tab1, text ='Tab 1') nb.add(tab2, text ='Tab 2') nb.pack(expand = 1, fill ="both") def on_tab_change(event): global firstTime1, firstTime2 tab = event.widget.tab('current','text') if tab == 'Tab 1': print('Tab 1') if firstTime1 == 1: gen_t1(tab1) firstTime1 = 0 elif tab == 'Tab 2': print('Tab 2') if firstTime2 == 1: gen_t2(tab2) firstTime2 = 0 nb.bind('<>', on_tab_change) root.mainloop() -- https://mail.python.org/mailman/listinfo/python-list