【问题标题】:print message in lower tk frame?在较低的 tk 框架中打印消息?
【发布时间】:2020-04-10 17:12:00
【问题描述】:

当我单击按钮时,我想在下部 tk 框架中显示的信息出现在空闲 shell 中。我希望有人能告诉我如何解决这个问题? (我从这里删除了我的 api 详细信息)

import tkinter as tk
from tkinter import *
from PIL import ImageTk
from coinbase.wallet.client import Client
import json

client = Client(api_key, api_secret)
total = 0
message = []
accounts = client.get_accounts()
for wallet in accounts.data:
    message.append( str(wallet['name']) + ' ' +   str(wallet['native_balance']) )
    value = str( wallet['native_balance']).replace('USD','')
    total += float(value)
message.append( 'Total Balance: ' + 'USD ' + str(total) )

root = tk.Tk()
canvas = Canvas(width = 444, height = 444, bg = 'gray24')
canvas.pack(expand = YES, fill = BOTH)
image = ImageTk.PhotoImage(file = "/Users/dusty/Pictures/Background.jpg")
canvas.create_image(0, 0, image = image, anchor = NW)

frame = tk.Frame(root, bg='gray24', bd=5)
frame.place(relx=0.5, rely=0.1, relwidth=0.5, relheight=0.1, anchor='n')


button = tk.Button(frame, text="go", font=40, command=lambda: print('\n'.join( message )))
button.place(relx=0.7, relheight=1, relwidth=0.3)
entry = tk.Entry(frame, font=40)
entry.place(relwidth=0.65, relheight=1)
lower_frame = tk.Frame(root, bg='gray24', bd=10)
lower_frame.place(relx=0.5, rely=0.3, relwidth=0.5, relheight=0.5, anchor='n')


mainloop()

【问题讨论】:

    标签: python tkinter coinbase-api


    【解决方案1】:

    这会做你想做的,但是它使用 pysimplegui 而不是 tkinter

    import time
    import cbpro
    import numpy as np
    import datetime as dt
    import PySimpleGUI as sg
    
    auth_client = cbpro.AuthenticatedClient('780adsfasdfasdfbf45ff0aasdfasdf08fasdfa1',
    'ahahEgasd9OLTD5Tasdfasdfasdf/asdfasdf/asdf/asdf/adfQ9mJtRRyRDG961hadsfasdfNsg==',
    '0aadsjhfasdfasdn4rk')
    
    fiat = 'USD'
    coin = 'XTZ'
    currency = 'XTZ-USD'
    
    
    #get account id for chosen pair
    def account(iD):
     for account in auth_client.get_accounts():
      if account['currency'] == iD:
       return account['id']
    
    
    sg.theme('Black')
    
    layout = [[sg.Text(currency,size=(40,20),key='-OUTPUT-')],[sg.Button('Run'),sg.Button('Quit')]]
    
    window = sg.Window('Ellie | Algorithmic Trader', layout, alpha_channel=.9, grab_anywhere=True)
    
    
    
    while True: # Event Loop
    
        event, values = window.read()
        if event == 'Quit':
          window.close()
          break
    
        if event == 'Run':
          
            def update():
              price = float(auth_client.get_product_ticker(product_id=currency)['price']) 
              window['-OUTPUT-'].update(price)
    
            update()
    
    window.close()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-28
      • 2013-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多