I have made a little Quiz Game in Python. This was my first experience in programming Gui's in Python with Tkinter.
![]() ![]()
In general, I do not have much knowledge about graphic programming and have acquired the necessary knowledge through skimming internet articles and try and error. Accordingly, the code looks like sciolism and semi-professional structuring. That should be improved.
Nov 12, 2018 I need a music quiz for python, where a random song is stored in an external file. The artist and the first letter of each word in displayed The user has 2 chances to guess the song There must be a points system. More for correct on first guess preferably The game ends when they choose the incorrect answer twice.
I will not be able to avoid a good basic tutorial on graphic programming, I think. However, if you have tips for me how to improve the style I would be grateful to hear them. From tkinter import Tk, Frame, Label, Buttonfrom time import sleepclass Question:def init(self, question, answers, correctLetter):self.question = questionself.answers = answersself.correctLetter = correctLetterdef check(self, letter, view):global rightif(letter self.correctLetter):label = Label(view, text='Right!' )right += 1else:label = Label(view, text='Wrong!' Use a single importInstead of importing each individual class, I recommend importing the whole module with a short name. You can then use the short name as a prefix for all of your commands.
It makes your code a bit more self-documenting, especially if you mix both tkinter and ttk in the same application.For example: import tkinter as tk.window = tk.Tkbutton = tk.Button(window, text='Start', command=askQuestion)Separate widget creation from layoutIn my experience, the layout of a GUI changes a lot more than the actual widgets, especially early in development. By separating widget creation from widget layout, it makes debugging much easier. It also makes it much easier to visualize the layout just by looking at the code.Instead of this: Label(view, text=self.question).packButton(view, text=self.answers0, command=lambda.args: self.check('A', view)).packButton(view, text=self.answers1, command=lambda.args: self.check('B', view)).packButton(view, text=self.answers2, command=lambda.args: self.check('C', view)).packButton(view, text=self.answers3, command=lambda.args: self.check('D', view)).pack. I recommend this: label = Label(view, text=self.question)buttona = Button(view, text=self.answers0, command=lambda.args: self.check('A', view))buttonb = Button(view, text=self.answers1, command=lambda.args: self.check('B', view))buttonc = Button(view, text=self.answers2, command=lambda.args: self.check('C', view))buttond = Button(view, text=self.answers3, command=lambda.args: self.check('D', view))label.packbuttona.packbuttonb.packbuttonc.packbuttond.packExplicitly set side for packI recommend always explicitly setting the side for pack. Even though the default will likely never change, explicitly setting the side makes the code less ambiguous: label.pack(side='top')buttona.pack(side='top')buttonb.pack(side='top')buttonc.pack(side='top')buttond.pack(side='top').
Quiz-GameA simple quiz game built using Python Game Instructions.Check your Python version by typing python -version in terminal/cmd prompt.If version is python 3.x you can continue.If version is python 2.x, try: python3 -version.If you receive a version replace 'python' with 'python3' for the rest of these instructions below.Start the game: type python(3) question.py.The game will run in the terminal. Answer the first question - whether you want to start the game. Select(a) Start the game(b) Exit.Pick your interest(a) Science (b) History of India (c) Commerce (d)Technology (e)World GKYou'll be presented with domain specific questions.Read the general instructions prompt for point system information and how to answer the questions. Each question carries 2 points and there is a negative marking of -1 per question.Answer each question. At the end of the game, you will be provided with the feedback of your responses.
![]()
If incorrect, the correct answer will be displayed. You will also be provided a little insight into the question and your final score will be revealed to you.The game will exit on its own. To play again, follow instructions from step 2.If you find any bugs in the game, please visit to report the issue.
Enjoy the game! If you like it, do not forget to give your feedback of this repository! Contributors Diya Nag ChaudhuryAmitrajit BoseDavid John Coleman IIRyan J. WilsonCandace H-VSouvik MondalPrem MaliAayush SarkarRaghav KhullarPasan JayawickramaLinda OglesbeeKamuishchanchalv18dvfleet413CrisCrosManan311.
![]() Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |