【发布时间】:2014-05-07 09:56:56
【问题描述】:
所以基本上,这是我的代码:
from Tkinter import *
import math # import module matematika
import tkFont
import time
class PersamaanKuadrat:
def __init__(self, parent, title):
self.parent = parent
#self.parent.geometry("1280x560")
self.parent.title(title)
self.parent.protocol("WM_DELETE_WINDOW")
self.aturKomponen()
self.entP2.focus_set()
def aturKomponen(self):
self.customFont = tkFont.Font(family="Helvetica", size=18)
mainframe = Frame(self.parent, bg="grey", bd=1)
mainframe.pack(fill=BOTH, expand=YES)
# Label Rumus
Label(mainframe, text="PT PARKIR SEJAHTERA", bg="grey", font=self.customFont).place(relx=.055, rely=.1)
Label(mainframe, text="HARAP SIMPAN BAIK-BAIK TIKET ANDA", fg="red", bg="grey", font=self.customFont).place(relx=.055, rely=.25)
Label(mainframe, text="LANTAI 1", fg="red", bg="grey", font=self.customFont).place(relx=.55, rely=.35)
Label(mainframe, text="LANTAI 2", fg="red", bg="grey", font=self.customFont).place(relx=.55, rely=.65)
# input data:
Label(mainframe, text="1st input", bg="grey").place(relx=.05, rely=.35)
self.entP5 = Entry(mainframe)
self.entP5.place(relx=.15, rely=.35)
Label(mainframe, text="2nd input", bg="grey").place(relx=.05, rely=.40)
self.entP4 = Entry(mainframe)
self.entP4.place(relx=.15, rely=.40)
Label(mainframe, text="3rd input", bg="grey").place(relx=.05, rely=.45)
self.entP3 = Entry(mainframe)
self.entP3.place(relx=.15, rely=.45)
Label(mainframe, text="4th input", bg="grey").place(relx=.05, rely=.50)
self.entP2 = Entry(mainframe)
self.entP2.place(relx=.15, rely=.50)
Label(mainframe, text="5th input", bg="grey").place(relx=.05, rely=.55)
self.entP1 = Entry(mainframe)
self.entP1.place(relx=.15, rely=.55)
Label(mainframe, text="6th input", bg="grey").place(relx=.05, rely=.60)
self.entP0 = Entry(mainframe)
self.entP0.place(relx=.15, rely=.60)
self.btnCariAkar = Button(mainframe, text="ENTER!",
command=self.onCariAkar)
self.btnCariAkar.place(relx=.25, rely=.35)
btn1= Button(mainframe, padx=30, pady=30, text="A1", bg="white")
btn1.place(relx=.65, rely=.25)
btn2 = Button(mainframe, padx=30, pady=30, text="A2", bg="white")
btn2.place(relx=.80, rely=.25)
btn3 = Button(mainframe, padx=30, pady=30, text="B1", bg="white")
btn3.place(relx=.65, rely=.55)
btn4 = Button(mainframe, padx=30, pady=30, text="B2", bg="white")
btn4.place(relx=.80, rely=.55)
def onCariAkar(self, event=None):
A = float(self.entP5.get())
B = float(self.entP4.get())
C = float(self.entP3.get())
D = float(self.entP2.get())
E = float(self.entP1.get())
F = float(self.entP0.get())
disk = A+B+C+D+E+F
class JamDigital:
""" Kelas Jam Digital"""
def __init__(self, parent, title):
self.parent = parent
self.parent.title(title)
#buat variabel String untuk teks jam
self.teksJam = StringVar()
self.aturKomponen()
#melakukan looping untuk tampilan jam
self.update()
def aturKomponen(self):
mainframe = Frame(self.parent, bg="grey", bd=1)
mainframe.pack(fill=BOTH, expand=YES)
#teks jam dibuat dengan komponen Label, yang bisa berubah
#setiap waktu
self.lblJam = Label(mainframe, textvariable=self.teksJam,
font=('Helvetica', 40))
self.lblJam.place(relx=.05, rely=.45)
def update(self):
#strftime() berfungsi untuk merubah waktu secara lokal
#menjadi bentuk string yang kita inginkan.
datJam = time.strftime("%H:%M:%S", time.localtime())
#mengubah teks jam sesuai dengan waktu saat ini
self.teksJam.set(datJam)
#perubahan teks jam dalam selang waktu 1 detik (1000 ms)
self.timer = self.parent.after(1000, self.update)
if __name__ == '__main__':
root = Tk()
aplikasi = PersamaanKuadrat(root, "Tugas Akhir")
aplikasi = JamDigital(root, "Tugas Akhir")
root.mainloop()
如果我想更改右侧 4 个按钮的颜色 通过将第 1 个输入的值更改为第 6 个输入,我该怎么办。
例如:
如果我用 1 填充所有输入(第一个输入直到第 6 个输入),然后按 enter,'A1' 的背景颜色将变为黄色 如果我用 2 填充所有输入,然后按 enter 'A1' 的背景颜色将变为红色 如果我用其他数字填充所有输入,'A1 的背景颜色将变为绿色
我想不通,所以我需要帮助,谢谢
【问题讨论】:
-
那么,您在更改颜色或使用“if”语句方面需要帮助吗?
-
是的,我知道,你能帮帮我吗?
标签: python-2.7 button tkinter