The ToolKit 2: More research than I thought

So now that the GUI has been made(barely), it's time to start coding(I think). First thing first is to start figuring out how to access it and apparently all you need to do is put the UI file in the same file as the code, so I started up visual studio code and made a new folder, gave a neat name and immediately realized I didn't know what I was doing.......

So, after some googling and YouTube tutorials(thank you India) I got something like this:




I imported the stuff in the library that would actually let me code stuff. Next up, the class. It's supposed to neatly divide my code into sections, each with its own responsibilities. Think of them as tidy little code houses where everything has its place. Next is the super part is what I don't really get, but from what I am hearing is that it's supposed to call the parent (the class toolkit) and make sure it's always called first? I don't really get how, but I'll figure it out(maybe), then the following code "uic.loadui" ties the UI to the class and then, the show method revealed my lovely creation to the world, like the masterpiece that it is.

then I made a main method on line 27 where I would be executing the code and opening the window and the " if __name__ == '__main__' " part is apparently supposed to make sure the file executing is the main file, something something good coding etiquette, but hey what do I know? I'm over here stealing from the Indians as if I'm British or something. 

With a deep breath I click run and the UI opens!! Rectangles and buttons!! It was a glorious sight so at least I'm not totally useless at this.




unfortunately, there is still the coding part that needs to be done and I'm already exhausted after the 1.5-hour research time but let's at least make one button work before I pass out.


so eventually I realized that I need to change the UI, so I went back to the UI designer an added a stacked widget which apparently lets me add pages, it might not be the fanciest way and there's prolly a better way to do it, but not today! This is a place of innocent ignorance, mild laziness and inexperience 😁😁😁

after another 30 minutes of research, I realized that I had to go back to the UI designer again to give all of the button's names for me to use 😑. Forget fancy titles – I went for clarity with 'wordTempBtn,' 'leaveCalcBtn,' and 'closeWinBtn.' Now, let's see if this button squad can actually do anything, lets first start with.......the close button.

so still under the init I typed self.closeWinBtn.clicked.connect(self.close)
the UI was tied to the class so if you use "self" everything thats part of that class comes with it.
clicked is what the action you wanna do and connect( ) is the job you want it to do

so it goes target -> specific target -> action ->result of that action.

Magic, I guess.

seems simple enough I guess, I ran the it and it worked, the window closed but that being said this was the easiest one, Of course, the real challenge awaits – the mighty calculator, a boss among buttons.
unfortunately, I ran out of energy, so that is to be done next time.

Until then 

~~Justin Case












Comments

Quote of the day