Python Forum
[Tkinter] showing return from button on main screen
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] showing return from button on main screen
#1
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.
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()
Reply


Messages In This Thread
showing return from button on main screen - by blazejwiecha - Nov-19-2020, 05:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter showing image in button rwahdan 3 5,659 Jun-16-2021, 06:08 AM
Last Post: Yoriz
  [Kivy] Kivy pop up shows duplicate buttons from main screen CEKinch 0 1,970 Feb-05-2021, 05:40 PM
Last Post: CEKinch
  [PyQt] QPainter issue showing black screen mart79 0 2,011 May-06-2020, 12:02 PM
Last Post: mart79
  [Tkinter] Listbox and Button not showing Linuxdesire 2 3,869 Oct-05-2019, 06:33 PM
Last Post: woooee
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 5,040 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  “main thread is not in main loop” in Tkinter Long_r 1 24,328 Jun-26-2019, 11:00 PM
Last Post: metulburr
  [Tkinter] RE: status bar to return to the centre after 1 minute of clicking a button ? chano 6 4,729 May-27-2019, 04:24 PM
Last Post: Yoriz
  Unable to return value from callback function of a button in Python Tkinter nilaybnrj 4 20,836 Aug-05-2018, 11:01 PM
Last Post: woooee
  Tkinter touch screen button click ashtona 2 9,668 Apr-13-2018, 11:46 AM
Last Post: buran
  GTK main window calling a main window DennisT 4 6,826 Oct-19-2016, 09:36 PM
Last Post: DennisT

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020