everyone.
First of all, I am not sure if the question was praised properly but I tried as best as I could. Also, do note that I just started learning Python because I wanted to create a simple computer program I wanted to use. I wanted to ask question here because I encountered a problem that might seem easy to pros but I can't seem to figure out the solution.
Here is the code I wrote...
from tkinter import *
from tkinter import ttk
from PIL import Image, ImageTk
class Application(Frame):
def __init__(self, master):
ttk.Frame.__init__(self, master)
self.grid()
self.create_widgets()
self.FIDSIA_Amount()
def create_widgets(self):
self.label1 = Label(self, text='Type').grid(row=1, column=12, sticky=E)
self.Type = ttk.Combobox(self, width=7, textvariable=varSymbol, state="readonly")
self.Type['values'] = ('--------', 'A','B','C')
self.Type.grid(row=1, column=13)
self.Type.bind("<<ComboboxSelected>>", self.adjustmentFIDSIA_Planet1)
def adjustmentFIDSIA_Planet1(self, event):
content = self.Type.get()
if content == 'A':
varP1f = 0
varP1ind = 12
varP1d = 1
varP1s = 0
varP1inf = 0
varP1app = -15
elif content == 'B':
varP1f = 0
varP1ind = 12
varP1d = 1
varP1s = 0
varP1inf = 0
varP1app = -10
elif content == 'C':
varP1f = 0
varP1ind = 12
varP1d = 1
varP1s = 0
varP1inf = 0
varP1app = -5
elif content == '--------':
varP1f = 0
varP1ind = 0
varP1d = 0
varP1s = 0
varP1inf = 0
varP1app = 0
def FIDSIA_Amount(self):
amountf = Label(self, textvariable=varP1F)
amountf.grid(row=1, column=1)
amountind = Label(self, textvariable=varP1Ind)
amountind.grid(row=1, column=3)
amountd = Label(self, textvariable=varP1D)
amountd.grid(row=1, column=5)
amounts = Label(self, textvariable=varP1S)
amounts.grid(row=1, column=7)
amountinf = Label(self, textvariable=varP1Inf)
amountinf.grid(row=1, column=9)
amountapp = Label(self, textvariable=varP1App)
amountapp.grid(row=1, column=11)
root = Tk()
varP1f = IntVar(root)
varP1ind = IntVar(root)
varP1d = IntVar(root)
varP1s = IntVar(root)
varP1inf = IntVar(root)
varP1app = IntVar(root)
varSymbol = StringVar(root, value='--------')
varP1F = StringVar(root)
varP1F.set(str(0+varP1f.get()))
varP1Ind = StringVar(root)
varP1Ind.set(str(0+varP1ind.get()))
varP1D = StringVar(root)
varP1D.set(str(0+varP1d.get()))
varP1S = StringVar(root)
varP1S.set(str(0+varP1s.get()))
varP1Inf = StringVar(root)
varP1Inf.set(str(0+varP1inf.get()))
varP1App = StringVar(root)
varP1App.set(str(0+varP1app.get()))
app = Application(root)
root.mainloop()
So, basically, I created a window with 6 numbers in it and next to it, there is a combobox dropdown menu listing 4 items (--------, A, B, C). What I want to do is when -------- is selected in combobox, I want 6 digits to be 0. However, if I select A in combobox, I want the 6 digits to be updated in the window by adding each of the 6 variables on 0. So, when I choose A, it will look like "0 12 1 0 0 -15" instead of "0 0 0 0 0 0". With current code, I can't seem to do it. PyCharm shows 6 variables: varP1f, etc... have error -> local variable value is not used.
How can I fix this problem?