Nov-19-2020, 05:02 PM
Hello,
first sorry for English and code, I am beginner :)
So , the problem I stuck with is that I wish to execute buttons on the screen of tkinter. For now with lots of problems I got to execute on terminal from PyCharm.
Any suggestions will be helpful.
first sorry for English and code, I am beginner :)
So , the problem I stuck with is that I wish to execute buttons on the screen of tkinter. For now with lots of problems I got to execute on terminal from PyCharm.
Any suggestions will be helpful.
import tkinter as tk import random import os import subprocess from subprocess import call, Popen, PIPE TYTUL = "Network helper" PRZYCISKI = [ "Ping Google", "Lista kart sieciowych", "Flush DNS", ] # # Ustawiam Tkinter # okno = tk.Tk() okno.title(TYTUL) # # Funkcje # def czysc_ekran(): # Ta funkcja wyczysci pole tekstowe z calego tekstu ekran.delete('1.0', "end") def aktu_ekran(zawartosc): # Ta funkcja wypisuje "zawartosc" w polu tekstowym ekran.insert("end", zawartosc + "\n") def zbierz_zaznaczone(): # Zbiera te wartosci, które zostaly zaznaczone zebrane = [] for x in dic_przyciski.items(): if x[1].get() == True: zebrane.append(x[0]) return zebrane def ping_google(): # Wypisuje w polu tekstowym ping z Google.com #if ping_google(): czysc_ekran() ekran.insert("end", os.system("ping google.com") + "\n") #aktu_ekran(os.system("ping google.com")) #for x in (os.system("ping google.com")): aktu_ekran(x) #else: # aktu_ekran("Brak zaznaczonych miejsc!") #print('Wyszedłeś na świat za pomocą hosta Google') #os.system("ping google.com") def lista_kart(): # Wypisuje w polu tekstowym wszystkie zaznaczone wartosci if zebrana_lista(): czysc_ekran() aktu_ekran(os.system("ifconfig")) for x in zebrana_lista(): aktu_ekran(x) else: aktu_ekran("Brak zaznaczonych miejsc!") def flush_dns(): # Wypisuje w polu tekstowym wszystkie zaznaczone wartosci if flushed_dns(): czysc_ekran() aktu_ekran("Zaznaczone są:") for x in flushed_dns(): aktu_ekran(x) else: aktu_ekran("Brak zaznaczonych miejsc!") # # Ustawiam Framy # frame_l = tk.Frame(okno) frame_l.pack(side = "left", fill = "both") frame_r = tk.Frame(okno) frame_r.pack(side = "right", fill = "both") # # Ustawiam lewy Frame # Lista checkboxów # W tym Frame zastosuje .pack() do organizacji # Slownik dajacy kazdej miejscowce jej wlasne tk.IntVar() dic_przyciski = {} for x in PRZYCISKI: dic_przyciski[x] = tk.IntVar() # Checkboxy for x in dic_przyciski.items(): tk.Checkbutton(frame_l, text = x[0], variable = x[1], anchor = "w").pack(side = "top", fill = "both") # # Ustawiam prawy Frame # Pole tekstowe i przyciski # W tym Frame zastosuje .grid() do organizacji # Pole tekstowe ekran = tk.Text(frame_r, height = 25, width = 40) ekran.grid(row = 0, column=0, columnspan=5) # Przyciski tk.Button(frame_r, text = PRZYCISKI[0], command = lambda:ping_google()).grid(row = 1, column = 0) tk.Button(frame_r,text = PRZYCISKI[1],command= lambda:lista_kart()).grid(row = 1 , column = 1) tk.Button(frame_r,text = PRZYCISKI[2],command= lambda:flush_dns()).grid(row = 1 , column = 2) # # Tkinter mainloop # okno.mainloop()