import tkinter as tk
from tkinter import messagebox
import MetaTrader5 as mt5
def main():
# Create the main window
root = tk.Tk()
root.title("MT4MYM-A")
# Set the window size
root.geometry("800x600")
# Create a frame for the login UI
login_frame = tk.Frame(root, width=400, height=600, bg="lightgrey")
login_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# Title for the login UI
login_title = tk.Label(login_frame, text="", font=("Helvetica", 20), bg="lightgrey")
login_title.pack(pady=20)
# Login fields
login_label = tk.Label(login_frame, text="Login:", font=("Helvetica", 14), bg="lightgrey")
login_label.pack(pady=5)
login_entry = tk.Entry(login_frame, font=("Helvetica", 14))
login_entry.pack(pady=5)
login_entry.insert(0, "5027341082") # Pre-fill with your login
password_label = tk.Label(login_frame, text="Password:", font=("Helvetica", 14), bg="lightgrey")
password_label.pack(pady=5)
password_entry = tk.Entry(login_frame, show="*", font=("Helvetica", 14))
password_entry.pack(pady=5)
password_entry.insert(0, "IxS@Po1b") # Pre-fill with your password
server_label = tk.Label(login_frame, text="Server:", font=("Helvetica", 14), bg="lightgrey")
server_label.pack(pady=5)
server_entry = tk.Entry(login_frame, font=("Helvetica", 14))
server_entry.pack(pady=5)
server_entry.insert(0, "MetaQuotes-Demo") # Pre-fill with your server
# Connect button
connect_button = tk.Button(login_frame, text="Connect", font=("Helvetica", 14), command=lambda: connect_to_mt5(login_entry.get(), password_entry.get(), server_entry.get(), root))
connect_button.pack(pady=20)
# Create a frame for the main content
main_frame = tk.Frame(root, width=400, height=600)
main_frame.pack(side=tk.RIGHT, fill=tk.BOTH, expand=True)
# Create a label with the text "🏧 MT4MYM-A"
label = tk.Label(main_frame, text="🏧 MT4MYM-A", font=("Helvetica", 24))
label.pack(expand=True)
# Create a label with the text "Loading..." at the bottom
loading_label = tk.Label(main_frame, text="Loading...", font=("Helvetica", 14))
loading_label.pack(side=tk.BOTTOM, pady=10)
# Start the Tkinter event loop
root.mainloop()
def connect_to_mt5(login, password, server, root):
# Initialize MetaTrader 5
if not mt5.initialize():
messagebox.showerror("Error", "initialize() failed")
mt5.shutdown()
return
# Log in to the MetaTrader 5 account
authorized = mt5.login(login=int(login), password=password, server=server)
if authorized:
print("Connected to MetaTrader 5")
display_account_info(root)
else:
messagebox.showerror("Error", "Failed to connect to MetaTrader 5")
def display_account_info(root):
# Get account info
account_info = mt5.account_info()
if account_info is None:
messagebox.showerror("Error", "Failed to get account info")
return
# Create a new window for account information
info_window = tk.Toplevel(root)
info_window.title("Account Information")
info_window.geometry("400x300")
# Display account information
info_labels = [
f"Account ID: {account_info.login}",
f"Balance: {account_info.balance}",
f"Equity: {account_info.equity}",
f"Margin: {account_info.margin}",
f"Free Margin: {account_info.margin_free}",
f"Leverage: {account_info.leverage}"
]
for info in info_labels:
label = tk.Label(info_window, text=info, font=("Helvetica", 14))
label.pack(pady=5)
if __name__ == "__main__":
main()
No comments:
Post a Comment