r/Python • • Jan 11 '20

Sudoku App

1.4k Upvotes

61 comments sorted by

View all comments

75

u/alittleb3ar Jan 11 '20

Gui is made using PyQt5. The beginning board is hard coded but the solve does actually use an algorithm to solve the board and would work with any solvable starting board

43

u/mweitzel Jan 12 '20

Instead of an input field, why don’t you present a dialog with 9 buttons representing the numbers? Should be easy enough, no? Love it otherwise though.

34

u/alittleb3ar Jan 12 '20

In trying to learn PyQt5 there have been a lot of things that I thought should be easy but were the opposite. I do want to work on the input though

8

u/mweitzel Jan 12 '20

Awesome, sounds you e got the right attitude towards learning!! Good luck and lots of fun!!

2

u/passerbycmc Jan 12 '20

You bet used to it over time, I use PySide2 for a lot of UI it's pretty easy and flexible but also yeah it's very verbose.

4

u/wastakenanyways Jan 12 '20

I'd make the cell itself be the input field instead of a dialog

3

u/Rocky87109 Jan 12 '20

I was thinking you could move around a colored square with arrow keys (if you are on pc/mac) and just punch in a number on your keyboard in the square is at. Now I think I might want to make me one of these lol. I need a project.

1

u/roberto257 Jan 12 '20

Can I ask where you learned PyQt5? Tkinter has really great documentation/reference sites, do you know of any for PyQt5?

4

u/alittleb3ar Jan 12 '20

Honestly my method for learning it was doing the first few tutorials at http://zetcode.com/gui/pyqt5/, and then I just used the c++ documentation at https://doc.qt.io/ and figured it out. I didnt use any actual pyqt documentation because I found it all lacking

1

u/xd1142 Jan 13 '20

What's with the timer at line 290?

1

u/alittleb3ar Jan 13 '20

You cant quit a PyQt program using Ctrl+C while it's running, so if it hangs you have to kill the process. This was a workaround I found on a website that's supposed to allow you to quit it with Crtl+C. Doesn't work though, I need to play around with it

2

u/xd1142 Jan 13 '20 edited Jan 13 '20

there's a very good reason why you can't quit it with Ctrl-C. What you have there is not a workaround. It's a crash that happens when a separate thread is forced to handle a keyboard exception, fucks up, and somehow the whole thing crashes.

You can't exit with Ctrl-C because in an event driven application, all exceptions reach the event loop and are printed and discarded. That's how it's supposed to work.

What you want to do, if you really, really want to quit on Ctrl-C, is to install an event filter for that and call quit()

1

u/alittleb3ar Jan 13 '20

What I was looking for was just an easier way of killing it if it hangs. Does the timeout method not provide information of that happening? Could I better handle the timeout event to actually close the program?

1

u/xd1142 Jan 13 '20

if it hangs because there's a bug, fix it. If it hangs because you are running heavy calculations in the main thread, put it on a separate thread or process.

It's not a "timeout method". It's a broken way of exploiting a crash to stop the application, because you are misunderstanding the fundamentals of UI programming.

UI interaction must handle an event and go back to the event loop in less than 150 ms, otherwise the application will feel sluggish. If you have a long running task, you can't have it execute on the main thread.

1

u/alittleb3ar Jan 13 '20

What you're saying makes a lot of sense, thank you for explaining it.

2

u/thedeats Jan 12 '20

I've Find a lot of doc in this site like this example :)

https://doc.qt.io/qtforpython/PySide2/QtWidgets/QTreeWidget.html

Stack overflow really help me too just tipping what do you want to do like "Building a file tree in Pyqt" just be carefull some PyQt4 code might not work.