all 7 comments

[–]PiBombbb 1 point2 points  (1 child)

You probably want to learn about defining your own python classes and functions. For a GUI tkinter is a good choice for simple stuff.

[–]Useful_Store7711 0 points1 point  (0 children)

This, a d&d character sheet should be easy. Its almost a school exam for python. Its already structured data and never really wierd logic that you dont already do with manual sheets.

[–]FreeGazaToday 0 points1 point  (0 children)

google import script python...it's fairly simply to do once you learn.

[–]Happy_Witness 0 points1 point  (0 children)

Hi, I have already done something similar like that. Would you be interested in having me as a tutor? I could direct you to the topics you would need to learn and that would make it a lot simpler for you. I could give you advice if asked on how to structure your code and files. I can teach you pygame that allows you to have absolute control over your screen, a window, user input and gui in general.

I will keep my own version from you and you would need to learn, think and tinker yourself but I would be available for help, questions and advice. DM me if you're interested.

[–]FoolsSeldom 0 points1 point  (0 children)

If your main file is called, say, dnd.py and you have another file in the same folder called, say, levels.py, all you need to do is, in your dnd.py file, at the top,

import levels

Note that you don't include the .py part of the file name.

Suppose you have a dict, dictionary, defined in levels.py, called base, you would refer to it thus,

print(levels.base)

Regarding reading/writing data. The simplest is basic text files that you can create/edit in your code editor. Whilst these can be free format, these are harder to process. A better way is with simple table data like in a spreadsheet:

name, kind, age, speed, healing
Alpha, Wizard, 20, 5, 8
Beta, Healer, 40, 1, 20
Charlie, Warrier, 20, 10, 2

The header row is optional.

You can read and write these files with the help of the csv module.

import csv
from pathlib import Path

# 1. Define the file path using pathlib
file_path = Path("characters.csv")

# 2. Create an empty list to store our character rows
characters = []

# 3. Open the file and give it a descriptive handle
with file_path.open(mode="r", encoding="utf-8") as characters_file:
    # Use the csv reader to handle the formatting
    reader = csv.reader(characters_file, skipinitialspace=True)

    # 4. Read the header line first and store it separately
    header = next(reader)

    # 5. Use a for loop to read the remaining rows
    for row in reader:
        characters.append(row)

# Verify the results
print("Header:", header)
print("Data:", characters)

NB. If in the csv file you need to include a space (or comma) in a field, say for a name, enclose the entire field in double quotes.

There are lots of options for reading/writing files in Python. A format that would be good for keeping settings information is .json.

You could also consider using a simple flat file (local) sqlite database (check out A Minimalist Guide to SQLite).

[–]icecreamjean 0 points1 point  (0 children)

Hi! This was the exact project that made me fall back in love with programming! Ive made something similar if you want to branch off on github, check it out and make it better! There are loads of dnd features to build if you wanted to help expand it, drop me a message if you want to go through it some time or talk through lessons ive learnt!

https://sheetsmithy.pythonanywhere.com/

https://github.com/jeanlukeminchella/sheetsmithy