Python Forum
Use Function in Tkinter Label
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use Function in Tkinter Label
#1
Hi i'm working on improving my code and making it clearer/shorter.

I'm having problems using the function i created. I can use this in Idle on the command line i.e Price(ripple) but not within the script.

Any ideas or a nudge in the right direction.

Look forward to any replies.

regards

J

from tkinter import *

import requests
import json

crypto =  {'ripple': '10', 'iota': '20'} # dictionary of crypto name and units pruchased

class Crypto:

    def __init__(self, coin, price):
        url = 'https://api.coinmarketcap.com/v1/ticker/'
        self.coin = coin
        self.price = price
        self.api = url + coin


def Price(self): #at command window type: Price(ripple)
           
        json_data = requests.get(self.api).json()
        dic = json.dumps(json_data)
        dict = json.loads(dic)[0]
        #print (dict)
        print (float(dict['price_usd']))
        #price = ("%.2f" %(dict['price_usd']))
        #pricefloat = str(round(price,2))
        #print = (pricefloat)

def URL(self): #at command window type: URL(ripple)
        print (self.api)


#rippleprice = Price(ripple) # this does not work

        
m=0
r=0
s=0

for key in crypto.keys():
    Label(text=key, relief=RIDGE, width=15).grid(row=r, column=0)
    r =r+1
for values in crypto.values():
    Label(text = values, relief=RIDGE, width=15).grid(row=m, column=1)
    m = m + 1
#Label(text = Price(ripple), relief=RIDGE, width=15).grid(row=0, column=2) # this does not work

mainloop()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to open a popup window in tkinter with entry,label and button lunacy90 1 810 Sep-01-2023, 12:07 AM
Last Post: lunacy90
  Add label to matplotlib function Pedroski55 2 1,651 Sep-23-2020, 12:46 AM
Last Post: Pedroski55
  OOP Label In Tkinter Harshil 2 1,896 Aug-21-2020, 07:14 PM
Last Post: bowlofred
  Partial using Tkinter function chesschaser 10 6,650 Jul-03-2020, 03:57 PM
Last Post: chesschaser
  Use a button in Tkinter to run a Python function Pedroski55 4 3,196 Jun-28-2020, 05:02 AM
Last Post: ndc85430
  Function assigned at a button in tkinter riccardoob 9 4,099 Oct-06-2019, 11:14 AM
Last Post: riccardoob

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020