Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
frdbonif authored Aug 14, 2020
1 parent 16a1dc6 commit aa8b219
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 33 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# tRandom
# tRandom v0.2

tRandom is a simple, cross-platform, psuedo-random number generator for games and draws. Written in Python using tkinter.

Expand All @@ -12,7 +12,9 @@ I created tRandom while a Python beginner, I was attempting to gain experience a

# Installing

A deb package is included for v0.0.1 with two minor know issues. This has only been tested on Ubuntu 18.04, but being a 100% Python application with only included packages imported, it should run happily all over the place.
A deb package is available for v0.2 with two minor know issues. This has only been tested on Ubuntu 18.04, but being a 100% Python application with only included packages imported, it should run happily all over the place.

To install elsewhere, the `tRandom.py` and `icon.png` files should be kept in the same folder, as long as you have the dependencies listed below installed, you will be able to launch the `tRandom.py` file directly. On Windows devices you may want to rename the `py` file to `tRandom.pyw` which will launch the program without a console window opening.

# Dependencies

Expand Down
4 changes: 2 additions & 2 deletions deb/DEBIAN/md5sums
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
6a91e7ab58b8a3342b4f880c4986efe4 ./generate-md5
d37067984cbee2c95aa4b16ad913051b ./usr/bin/trandom/icon.png
e0fb79ec59bc0abeb252a2d8000244cc ./usr/bin/trandom/tRandom.py
4ab174955a7466bb99e33122adbebde7 ./usr/share/appdata/trandom.appdata.xml
d957e5b75a648f0366d98982efd80ab6 ./usr/bin/trandom/tRandom.py
b28f95f50ad84f4648df4f7f1b0f486c ./usr/share/appdata/trandom.appdata.xml
3482502548b07b93d2897b4b6697fc84 ./usr/share/applications/trandom.desktop
79 changes: 51 additions & 28 deletions deb/usr/bin/trandom/tRandom.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/python3

# tRandom (C) Fred Boniface 2020, All Rights Reserved
# tRandom v0.2 (C) Fred Boniface 2020, All Rights Reserved

from tkinter import *
import tkinter.messagebox
Expand All @@ -14,24 +14,24 @@ def __init__(self, master=None):
self.master = master
self.pack(fill=BOTH, expand=1)

# Define class variables
# Define prevResults list
self.prevResults = [" ", " ", " ", " "," ", " ", " ", " "]

# Define Menu Bar and Contents
# Define Menu Bar
menu = Menu(self.master)
self.master.config(menu=menu)
fileMenu = Menu(menu)
menu.add_cascade(label="File", menu = fileMenu)
aboutMenu = Menu(menu)
menu.add_cascade(label="About", menu=aboutMenu)

# Define menu emtries
fileMenu.add_command(label="Exit", command=self.clickExit)
aboutMenu.add_command(label="Version", command=self.clickVersion)
aboutMenu.add_command(label='License', command=self.clickLic)
aboutMenu.add_command(label="About", command=self.clickAbout)

# Define window widgets

# Define top labels and entry boxes
l1 = Label(self, text="Enter the range of numbers below")
l1.place(x=5,y=10)
lIn1 = Label(self, text="Lowest Number:")
Expand All @@ -45,12 +45,15 @@ def __init__(self, master=None):
self.in2.place(x=150, y=70)
self.in2.insert(0,"100")

# Define result labels
self.l3 = Label(self, text="Your result:")
self.l3.place(x=5,y=100)
self.l2 = Label(self, font=("Courier", 55), fg="red")
self.l2.place(x=5,y=130)
self.l4 = Label(self, text="Past results:")
self.l4.place(x=160,y=100)

# Define past result labels
self.past1 = Label(self)
self.past1.place(x=165,y=120)
self.past2 = Label(self)
Expand All @@ -68,8 +71,7 @@ def __init__(self, master=None):
self.past8 = Label(self)
self.past8.place(x=205,y=180)



# Define bottom buttons
exitButton = Button(self, text="Exit", command=self.clickExit)
exitButton.place(x=5,y=225)

Expand All @@ -79,24 +81,30 @@ def __init__(self, master=None):
resetButton = Button(self, text="Reset", command=self.clickReset)
resetButton.place(x=75,y=225)

# Define Functions
# Define Functions

# Exit the program
def clickExit(self):
exit()

# Interger entry error popup
def intErr(self):
print("Oops!")
tkinter.messagebox.showerror('tRandom - Error','Make sure you only enter whole numbers below 1000.')
tkinter.messagebox.showerror('tRandom - Error','Make sure you only enter whole numbers between 0 and 999.')

# Software version informational popup
def clickVersion(self):
tkinter.messagebox.showinfo('tRandom - Version', 'Pre-release, unversioned\n(C) Fred Boniface 2020')
tkinter.messagebox.showinfo('tRandom - Version', 'v0.0.1\n(C) Fred Boniface 2020')

# About informational popup
def clickAbout(self):
tkinter.messagebox.showinfo('tRandom - About', 'An easy to use psuedo-random number generator written in Python 3.\n\nFor more information visit:\nhttps://tRandom.fjla.uk/')

# License informational popup
def clickLic(self):
tkinter.messagebox.showinfo('tRandom - License', 'tRandom is licensed under the GPLv3. A copy of this license is included with the software, for more information visit:\nhttps://trandom.fjla.uk/')

# Reset function.
def clickReset(self):
self.prevResults.clear()
self.prevResults = [" ", " ", " ", " "," ", " ", " ", " "]
Expand All @@ -110,39 +118,54 @@ def clickReset(self):
self.past7.config(text="")
self.past8.config(text="")

# Generate function.
def clickGenerate(self):

# Get strings from entry box
lowStr = self.in1.get()
highStr = self.in2.get()
print("Low: " + lowStr)
print("High: " + highStr)

# Try to get High & Low values as intergers
# Try to convert strings to intergers or show error box
try:
lowInt = int(lowStr)
highInt = int(highStr)
highInt += 1
except:
self.intErr()

result = random.randrange(lowInt,highInt)
print("Result:")
print(result)
self.prevResults.append(result)
print(self.prevResults)

self.l2.config(text=result)
self.past1.config(text=self.prevResults[-1])
self.past2.config(text=self.prevResults[-2])
self.past3.config(text=self.prevResults[-3])
self.past4.config(text=self.prevResults[-4])
self.past5.config(text=self.prevResults[-5])
self.past6.config(text=self.prevResults[-6])
self.past7.config(text=self.prevResults[-7])
self.past8.config(text=self.prevResults[-8])

# Check that the intergers are within range
if highInt > 1000:
self.intErr()
elif lowInt < 0:
self.intErr()
else:

# Generate the random number and print to console
result = random.randrange(lowInt,highInt)
print("Result:")
print(result)

# Append to prevResults print list to console
self.prevResults.append(result)
print(self.prevResults)

# Print result and prevResults to interface
self.l2.config(text=result)
self.past1.config(text=self.prevResults[-1])
self.past2.config(text=self.prevResults[-2])
self.past3.config(text=self.prevResults[-3])
self.past4.config(text=self.prevResults[-4])
self.past5.config(text=self.prevResults[-5])
self.past6.config(text=self.prevResults[-6])
self.past7.config(text=self.prevResults[-7])
self.past8.config(text=self.prevResults[-8])

# Main
root = Tk()
app = Window(root)
root.iconphoto(False, PhotoImage(file='/usr/bin/trandom/icon.png'))
root.iconphoto(False, PhotoImage(file='icon.png'))
root.wm_title("tRandom")
root.geometry("250x260")
root.mainloop()
2 changes: 1 addition & 1 deletion tRandom.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/python3

# tRandom (C) Fred Boniface 2020, All Rights Reserved
# tRandom v0.2 (C) Fred Boniface 2020, All Rights Reserved

from tkinter import *
import tkinter.messagebox
Expand Down

0 comments on commit aa8b219

Please sign in to comment.