From aa8b219451b09d99f52d2990240982803d0e8591 Mon Sep 17 00:00:00 2001 From: frdbonif <65509453+frdbonif@users.noreply.github.com> Date: Fri, 14 Aug 2020 11:40:40 +0100 Subject: [PATCH] Add files via upload --- README.md | 6 ++- deb/DEBIAN/md5sums | 4 +- deb/usr/bin/trandom/tRandom.py | 79 ++++++++++++++++++++++------------ tRandom.py | 2 +- 4 files changed, 58 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 92e7e4d..706910f 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 diff --git a/deb/DEBIAN/md5sums b/deb/DEBIAN/md5sums index cf4bf79..1ffb035 100644 --- a/deb/DEBIAN/md5sums +++ b/deb/DEBIAN/md5sums @@ -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 diff --git a/deb/usr/bin/trandom/tRandom.py b/deb/usr/bin/trandom/tRandom.py index 248a566..fcc109b 100644 --- a/deb/usr/bin/trandom/tRandom.py +++ b/deb/usr/bin/trandom/tRandom.py @@ -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 @@ -14,10 +14,10 @@ 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) @@ -25,13 +25,13 @@ def __init__(self, master=None): 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:") @@ -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) @@ -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) @@ -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 = [" ", " ", " ", " "," ", " ", " ", " "] @@ -110,13 +118,16 @@ 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) @@ -124,25 +135,37 @@ def clickGenerate(self): 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() diff --git a/tRandom.py b/tRandom.py index 4d42889..fcc109b 100644 --- a/tRandom.py +++ b/tRandom.py @@ -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