Skip to content

added json config file for changing and reading from default. #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions Fluent Calculator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from tkinter import ttk
import tkinter as tk
from tkinter import*
from tkinter import *
import json

with open("config.json", "r") as config:
data = json.load(config)

print(data)

def btnClick(numbers) :
global operator
Expand All @@ -19,21 +25,32 @@ def btnEqualsInput():
operator=""

def setdarkmode():
if darkmode.get() == 1:
# cal.tk.call("source", "sun-valley.tcl")
if darkmode.get() == True:
cal.tk.call("set_theme", "dark") #You can change to "dark"
data['darkmode'] = 'True'
else:
# cal.tk.call("source", "sun-valley.tcl")
cal.tk.call("set_theme", "light") #You can change to "dark"
data['darkmode'] = 'False'

updateConfig()

def updateConfig():
with open("config.json", "w") as jsonfile:
json.dump(data, jsonfile)
jsonfile.close()

cal = Tk()
cal.title('Fluent Calculator')

menubar = Menu(cal)
darkmode = tk.BooleanVar()
darkmode.set(False)

menubar.add_checkbutton(label="Dark Mode", onvalue=1, offvalue=0, variable=darkmode, command=setdarkmode)
if data['darkmode'] == "True":
darkmode.set(True)
else:
darkmode.set(False)

menubar.add_checkbutton(label="Dark Mode", onvalue=True, offvalue=False, variable=darkmode, command=setdarkmode)

operator=""
tex_input= StringVar()
Expand Down Expand Up @@ -73,7 +90,7 @@ def setdarkmode():
Divsion=ttk.Button(cal, text=":", command=lambda:btnClick("/")). grid(row=5, column=3, padx= 8, pady= 0, ipadx=5, ipady=5)

cal.tk.call("source", "sun-valley.tcl")
cal.tk.call("set_theme", "light") #You can change to "dark"
setdarkmode() # Calls the function initially to repreasent what user expects from config, if not True then defaults to light mode

#Min width for the calculator
cal.update()
Expand Down
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"darkmode": "False"}