Skip to content

Instantly share code, notes, and snippets.

@ROBOMASTER-S1
Last active March 10, 2023 08:10
Show Gist options
  • Save ROBOMASTER-S1/41be3ec7a6693ebc9e9322ac6a1a5789 to your computer and use it in GitHub Desktop.
Save ROBOMASTER-S1/41be3ec7a6693ebc9e9322ac6a1a5789 to your computer and use it in GitHub Desktop.
Tk Laser Wars Screensaver Python Program Examples: Created by Joseph C. Richardson
'''
Have some fun with this little tkinter laser wars Python program example:
'''
# Created by Joseph C. Richardson, GitHub.com
from tkinter import*
from random import*
import time
my_window=Tk()
my_window.title('LASER WARS')
def random_colour_code():
hex_chars=['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']
colour_code='#'
for i in range(0,6):
colour_code=colour_code+choice(hex_chars)
return colour_code
my_canvas=Canvas(my_window,width=1920,height=1080,background='#000000')
my_canvas.grid(row=0,column=0)
while True:
x1=randint(-500,1920)
y1=randint(-500,1920)
x2=randint(-500,1920)
y2=randint(-500,1920)
x3=randint(-500,1920)
y3=randint(-500,1920)
x4=randint(-500,1920)
y4=randint(-500,1920)
x5=randint(-500,1920)
y5=randint(-500,1920)
x6=randint(-500,1920)
y6=randint(-500,1920)
random_width=randint(0,10)
my_canvas.create_line(x1,y1,x2,y2,fill=random_colour_code(),width=random_width)
my_canvas.create_line(x3,y3,x4,y4,fill=random_colour_code(),width=random_width)
my_canvas.create_line(x5,y5,x6,y6,fill=random_colour_code(),width=random_width)
my_canvas.update()
time.sleep(.05)
my_canvas.delete('all')
my_window.mainloop()
'''
Not: if you wish to pack strings in Tk, you must use semicolons (;) as separators.
x1=randint(-500,1920);y1=randint(-500,1920)
x2=randint(-500,1920);y2=randint(-500,1920)
x3=randint(-500,1920);y3=randint(-500,1920)
x4=randint(-500,1920);y4=randint(-500,1920)
x5=randint(-500,1920);y5=randint(-500,1920)
x6=randint(-500,1920);y6=randint(-500,1920)
'''
@ROBOMASTER-S1
Copy link
Author

ROBOMASTER-S1 commented Mar 7, 2023

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment