tkinter 질문입니다. (출력값 만들기가 안돼요.)
조회수 965회
배경설명 : 입력값은 만들었는데, 계산식을 대입한 출력값을 어떻게 써야하는 지 모르겠습니다. Length, height가 입력값이면 오른쪽 파란색에 예를 들면 면적값이 나오게 하고 싶습니다. 예전에 다른 코드를 카피(!) 했을때는 float로 숫자입력하고 entry로 입,출력값이 나오게 했었는데 지금은 제가 카피를 여기저기서 해오는 바람에 어떤 걸로 넣어야 할지 모르겠습니다. 아래 코드는 꽤 깁니다. 참고용이니까, 혹시 출력값을 어떻게 쓰는지만 알고싶습니다.
(설명하자면 첫페이지에 숫자를 넣으면 그 숫자만큼 열이 생성됩니다. 거기까지는 했는데 length를 넣으면 계산값 입력을 어떻게 해야할 지 모르겠습니다. height값이 없으니 그냥 제곱값이라도 어떻게 구성해야할지만 알려주세요! 감사합니다)
from tkinter import *
import tkinter.messagebox
class Planificador(Frame):
def __init__(self,master):
Frame.__init__(self, master)
self.master = master
self.initUI()
def initUI(self):
self.master.title("Expectaion of Temperature")
self.frameOne = Frame(self.master)
self.frameOne.grid(row=0,column=0)
self.frameTwo = Frame(self.master)
self.frameTwo.grid(row=1, column=0)
self.canvas=Canvas(self.frameTwo)
self.listFrame=Frame(self.canvas)
self.scrollb=Scrollbar(self.master, orient="vertical",command=self.canvas.yview)
self.scrollb.grid(row=1, column=1, sticky='nsew')
self.canvas['yscrollcommand'] = self.scrollb.set
self.canvas.create_window((0,0),window=self.listFrame,anchor='nw')
self.listFrame.bind("<Configure>", self.AuxscrollFunction)
self.scrollb.grid_forget()
self.canvas.pack(side="left")
self.frameThree = Frame(self.master)
self.frameThree.grid(row=2, column=0)
# 1st frame
self.txt = Text(self)
self.txt.pack(fill=BOTH, expand=1)
self.chipstext = Label(self.frameOne, text = " Amount of chips ", justify="center")
self.chipstext.grid(row=1, column=0)
self.entrychips = Entry(self.frameOne,width=3)
self.entrychips.grid(row=2, column=0, pady=(5,5))
self.acceptnumchips = Button(self.frameOne,text="Click me!", command=self.accept_chips,width=8)
self.acceptnumchips.grid(row=6, column=0, pady=(5,5))
def AuxscrollFunction(self,event):
#You need to set a max size for frameTwo. Otherwise, it will grow as needed, and scrollbar do not act
self.canvas.configure(scrollregion=self.canvas.bbox("all"),width=1200,height=500)
def accept_chips(self):
try:
val = int(self.entrychips.get())
self.accept_chips_ok()
self.scrollb.grid(row=1, column=1, sticky='nsew')
except ValueError:
tkinter.messagebox.showerror(title='입력 오류', message='부품의 개수를 자연수로 입력해주세요')
def accept_chips_ok(self):
self.num_chips = self.entrychips.get()
self.chipstext.grid_remove()
self.entrychips.grid_remove()
self.acceptnumchips.grid_remove()
self.optionmenus_chips = list()
self.length = []
self.numerolotes = []
self.optionmenus_Convection = list()
self.lotes = list()
self.mischips = ['CPU', 'eMMC', 'PMIC', 'ethernet']
self.n = 1
while self.n <= int(self.num_chips):
def cal():
temp = self.lengthchips
self.temperature.insert(1, 'hello')
#column[0-1]
self.textochip = Label(self.listFrame, text = "chip: ", justify="left")
self.textochip.grid(row=self.n, column=0)
var = StringVar()
menu = OptionMenu(self.listFrame, var, *self.mischips)
menu.config(width=8)
menu.grid(row=self.n, column=1)
var.set("Component")
self.optionmenus_chips.append((menu, var))
#column[2- 3]
self.lengthtext = Label(self.listFrame, text = "Length[mm]: ", justify="center")
self.lengthtext.grid(row=self.n, column=2, padx=(10,0))
self.lengthchips = Entry(self.listFrame, width = 3)
self.lengthchips.grid(row=self.n, column=3, padx=(0,10))
self.lengthchips.insert(0, "0")
self.widthtext = Label(self.listFrame, text = "Width[mm]: ", justify="center")
self.widthtext.grid(row=self.n, column=4, padx=(10,0))
self.widthchips = Entry(self.listFrame,width=3)
self.widthchips.grid(row=self.n, column=5, padx=(0,10))
self.widthchips.insert(0, "0")
self.heighttext = Label(self.listFrame, text = "Height[mm]: ", justify="center")
self.heighttext.grid(row=self.n, column=6, padx=(10,0))
self.heightchips = Entry(self.listFrame,width=3)
self.heightchips.grid(row=self.n, column=7, padx=(0,10))
self.heightchips.insert(0, "0")
self.textoConvection = Label(self.listFrame, text = "Convection: ", justify="center")
self.textoConvection.grid(row=self.n, column=8)
var2 = StringVar()
menu2 = OptionMenu(self.listFrame, var2, "Natural", "Forced(Fan)")
menu2.config(width=5)
menu2.grid(row=self.n, column=9)
var2.set("Natural")
self.optionmenus_Convection.append((menu2, var2))
self.button = Button(self.listFrame, text = 'Submit', bg = 'black', fg = 'white', command = cal)
self.button.grid(row=int(self.n), column=10, padx = (10,0))
self.temperature = Entry(self.listFrame,width=5, justify = 'center')
self.temperature.grid(row=int(self.n), column=11, padx = (10,0))
self.n += 1
self.anadirchips = Button(self.frameThree, text="Add row", command=self.addchip, width=10)
self.anadirchips.grid(row=0, column=2, pady=(10,10))
def addchip(self):
self.textochipnuevo = Label(self.listFrame, text = "chip: ", justify="left")
self.textochipnuevo.grid(row=int(self.num_chips)+1, column=0)
var = StringVar()
menu = OptionMenu(self.listFrame, var, *self.mischips)
menu.grid(row=self.n, column=1)
menu.config(width= 8)
menu.grid(row=int(self.num_chips)+1, column=1)
var.set("Component")
self.optionmenus_chips.append((menu, var))
self.lengthtext = Label(self.listFrame, text = "Length[mm]: ", justify="center")
self.lengthtext.grid(row=int(self.num_chips)+1, column=2, padx=(10,0))
self.lengthchips = Entry(self.listFrame,width=3)
self.lengthchips.grid(row=int(self.num_chips)+1, column=3, padx=(0,10))
self.lengthchips.insert(0, "0")
self.widthtext = Label(self.listFrame, text = "Width[mm]: ", justify="center")
self.widthtext.grid(row=int(self.num_chips)+1, column=4, padx=(10,0))
self.widthchips = Entry(self.listFrame,width=3)
self.widthchips.grid(row=int(self.num_chips)+1, column=5, padx=(0,10))
self.widthchips.insert(0, "0")
self.heighttext = Label(self.listFrame, text = "Height[mm]: ", justify="center")
self.heighttext.grid(row=int(self.num_chips)+1, column=6, padx=(10,0))
self.heightchips = Entry(self.listFrame,width=3)
self.heightchips.grid(row=int(self.num_chips)+1, column=7, padx=(0,10))
self.heightchips.insert(0, "0")
self.textoConvection = Label(self.listFrame, text = "Convection: ", justify="center")
self.textoConvection.grid(row=int(self.num_chips)+1, column=8)
var2 = StringVar()
menu2 = OptionMenu(self.listFrame, var2, "Natural", "Forced")
menu2.config(width=5)
menu2.grid(row=int(self.num_chips)+1, column=9)
var2.set("Natural")
self.optionmenus_Convection.append((menu2, var2))
self.button = Button(self.listFrame, text="Submit", bg="black", fg="white")
self.button.grid(row=int(self.num_chips)+1, column=10, padx = (10,0))
self.temperature = Entry(self.listFrame,width=5, justify = 'center')
self.temperature.grid(row=int(self.num_chips)+1, column=11, padx=(10,0))
self.length.append(self.lengthchips)
self.num_chips = int(self.num_chips)+1
if __name__ == "__main__":
root = Tk()
aplicacion = Planificador(root)
root.mainloop()
-
(•́ ✖ •̀)
알 수 없는 사용자 - 〉
댓글 입력