Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
General Tech Learning Aids/Tools 2 years ago
Posted on 16 Aug 2022, this text provides information on Learning Aids/Tools related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
Disclaimer - Brand new to programming, with Python (3.x) being my choice of language to begin with.
I recently completed a Python course on codeacademy in which I created a mini battleships game. As a learning project I'm developing a GUI using Tkinter and Checkbuttons for the game board so that it can be played outside of the interpreter.
I'm now blocked as I don't know how to have Python randomly select the Checkbutton position for the battleship location - and keep it invisible from the player.
Here's my Tkinter code so far...
from tkinter import * class gui(object): def __init__(self): master = Tk() master.title("Battleships!") w = Label(master, text="Let's play Battleships!") w.pack() w = Label(master, text="Click in a box to try and bomb the Battleship:") w.pack() self.checkvar1 = IntVar() c = Checkbutton(master, variable=self.checkvar1, command=self.cb) c.pack() #Hopefully I can use this to display messages to user as they guess w = Label(master, text=" ") w.pack() Button(master, text="I give up!", command=master.quit).pack() master.mainloop() def cb(self): print("variable is", self.checkvar1.get()) return self.checkvar1.get() def main(): g = gui() if __name__ == '__main__': main()
Perhaps I should first create my Checkbutton Grid (5 x 5) instead of just trying it with a single Checkbutton (I was attempting to slice up my development into logical problems)?
Here is the original game code (no GUI)...
from random import randint board = [] for x in range(5): board.append(["O"] * 5) def print_board(board): for row in board: print(" ".join(row)) print("Let's play Battleship!") print_board(board) def random_row(board): return randint(0, len(board) - 1) def random_col(board REPLY 0 views 0 likes 0 shares Facebook Twitter Linked In WhatsApp
You could always generate all your checkboxes (while storing them in a list when you create them) and then choose an item randomly in the list, store it, and when the user clicks, compare the one he clicked to the one you've stored.
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
General Tech 9 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 2 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.