[Python] How can I call two variables from a class of another script (tkinter) so they are...

Discussão em 'Python' iniciado por Stack, Fevereiro 4, 2025.

  1. Stack

    Stack Membro Participativo

    I have two scripts, one is the main.py and the other has a class that has a TKinter IU. From the TKinter, it should get some variables, and those variables should be the input for the main.py.

    How can I make this possible?

    I've tried to do this, but it's only my second day with tkinter libraries and don't know much about classes.

    This is the supertrend02_tk.py (tkinter)

    import config
    from binance.client import Client
    from binance.enums import *
    from tkinter import *
    from tkcalendar import Calendar
    import tkinter as tk

    client = Client(config.API_KEY, config.API_SECRET, tld='com')

    exchange_info = client.get_exchange_info()


    class Window(Frame):
    def __init__(self, master=None):
    Frame.__init__(self, master)
    self.master = master
    self.pack() # Window is packed in its master.

    exitButton = Button(self, text="1st Run this", command=self.clickrunButton)
    exitButton.pack()

    def clickrunButton(self):
    self.run() # Now this work



    def run(self):
    def get_info():
    data=[]
    for s in exchange_info['symbols']:
    print(s['symbol'])
    data.append(s['symbol'])
    info_recibida = data

    return info_recibida

    OPTIONS = get_info()

    def on_change_selection(value):
    print(' value:', value)
    print('selected:', selected.get())

    master = Tk(className='SuperTrend Backtesting Bot')

    selected = tk.StringVar(master)
    selected.set(OPTIONS[0])

    w = OptionMenu(master, selected, *OPTIONS, command=on_change_selection)

    # set window size
    master.geometry("500x500")

    #master.mainloop()
    ####################################################
    # Add Calendar
    cal = Calendar(master, selectmode = 'day',
    year = 2022, month = 11,
    day = 13)

    cal.pack(pady = 20)

    def grad_date():
    date.config(text = "Selected Date is: " + cal.get_date())

    # Add Button and Label
    Button(root, text = "Get Date",
    command = grad_date).pack(pady = 20)

    date = Label(root, text = "")

    dia_inicial = cal.get_date()

    date.pack(pady = 20)

    w.pack()



    root = Tk()
    app = Window(root)

    # set window title
    root.wm_title("Supertrend")

    # show window
    root.mainloop()


    And the variables that I should use in the main.py are:

    from binance.client import Client

    from tkinter import *
    from tkcalendar import Calendar
    import tkinter as tk
    client = Client(config.API_KEY, config.API_SECRET, tld='com')

    exchange_info = client.get_exchange_info()
    import supertrend02_tk
    from supertrend02_tk import dia_inicial, selected

    plt.style.use('fivethirtyeight')
    plt.rcParams['figure.figsize'] = (20,10)

    print("cara_bobo")
    symbolo=selected
    print(symbolo)
    idate=dia_inicial
    print(idate)

    Continue reading...

Compartilhe esta Página