Advertisement
Guest User

Untitled

a guest
Dec 1st, 2021
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import ttk
  3. from tkinter import *
  4. import mysql.connector
  5.  
  6. def show():
  7. mysqldb = mysql.connector.connect(host="IP", user="User", password="User", database="pran")
  8. mycursor = mysqldb.cursor()
  9. mycursor.execute("Select Node, OM_Adress, OM_gateway, CPUP_Adress, CPUP_gateway From TX_address")
  10. records = mycursor.fetchall()
  11. print(records)
  12.  
  13. for i, (Node, OM_Adress, OM_gateway, CPUP_Adress, CPUP_gateway) in enumerate(records, start=1):
  14. listBox.insert("", "end", values=(Node, OM_Adress, OM_gateway, CPUP_Adress, CPUP_gateway))
  15. mysqldb.close()
  16.  
  17. root = tk.Tk()
  18. root.geometry("1200x600")
  19. root.title("IPnodes")
  20. label = tk.Label(root, text="IPnodes", font=("Arial",30)).grid(row=0, columnspan=3)
  21.  
  22. cols = ('Node', 'OM_Adress', 'OM_gateway','CPUP_Adress', 'CPUP_gateway')
  23.  
  24. scrolled_listbox = tk.Frame(root)
  25. scrolled_listbox.columnconfigure(0, weight=1)
  26. scrolled_listbox.rowconfigure(0, weight=1)
  27. scroll = ttk.Scrollbar(scrolled_listbox)
  28. scroll.grid(row=0, column=1, sticky="ns")
  29. listBox = ttk.Treeview(scrolled_listbox, columns=cols, show='headings')
  30. listBox.grid(row=0, column=0, sticky="nsew")
  31. scroll.configure(command=listBox.yview)
  32. listBox.configure(yscrollcommand=scroll.set)
  33. scrolled_listbox.grid(row=2, column=0, columnspan=4, sticky="nsew")
  34.  
  35. root.columnconfigure(1, weight=1)
  36. root.rowconfigure(1, weight=1)
  37.  
  38. for col in cols:
  39. listBox.heading(col, text=col)
  40. tk.Button(root, text="Close", width=15, command=exit).grid(row=4, column=1)
  41. show()
  42.  
  43. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement