簡體   English   中英

如何更正此函數以在Tkinter Python中創建標簽?

[英]How do I correct this function to create a label in Tkinter Python?

您能幫我解決這個問題嗎,所以請出現一個標簽:)? 我不認為這2個函數編寫正確,我是新手,需要幫助。...僅供參考,“轉換”功能由“#轉換按鈕”命令。

import sys
from Tkinter import *

root = Tk()
root.title("CURRENCY CONVERTER")
root.geometry('600x300+30+100')
root.config(bg="yellow", bd=5)

def rate():
        if var =='GBP' and var2 =='USD':
            rate=float(1.63452)
        if var == 'GBP' and var2=='EUR':
            rate=float(1.19529)
        else:
            rate=1
        return rate

def convert(rate):
        converted=Label(root, text=(var, entarr,">>>", (entarr*rate()), var2))
        converted.pack(expand=1)
        return convert

#title
Title=Label(root, text="Currency Converter")
Title.config(font=('century gothic',(35)),bg='red',width=0,relief=RAISED)
Title.pack(expand=1, anchor=CENTER)

#entry box
entarr = IntVar()
entry = Entry(root, textvariable=entarr)
entry.config(font=('century gothic',(15)),bg='yellow',width=5, relief=SOLID)
entry.pack(padx=10,pady=10, expand = 1)

#currency 1
var = StringVar(root)
var.set('Choose a currency to convert from')
choices = ['GBP', 'USD', 'EUR']
option = OptionMenu(root, var, *choices)
option.config(font=('century gothic',(15)),bg='yellow',activebackground='cyan',width=0, relief=FLAT)
option.pack(ipadx=40,ipady=0, expand=1)

#convert button
Arrow= Button(root, text=">>>>>>>>>", command = convert)
Arrow.config(font=('century gothic',(15)),width=0, bg="yellow", relief=SOLID)
Arrow.pack(ipadx=0,ipady=0, expand =1)

#currency 2
var2 = StringVar(root)
var2.set('Choose a currency to convert from')
choices2 = ['GBP','USD','EUR']
option2 = OptionMenu(root, var2, *choices2)
option2.config(font=('century gothic',(15)),bg='yellow',activebackground='cyan',width=0, relief=FLAT)
option2.pack(ipadx=40,ipady=0, expand=1)

root.mainloop()
def rate():
    rate = 1
    if var.get() =='GBP' and var2.get() =='USD':
        rate=float(1.63452)
    if var.get() == 'GBP' and var2.get()=='EUR':
        rate=float(1.19529)
    ## TODO:: add other convertion conditions
    return rate

def convert():
    converted=Label(root, text=(var.get(), entarr.get(),">>>", (entarr.get()*rate()), var2.get()))
    converted.pack(expand=1)
    return convert

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM