-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


[ ] ip- Python , Tkinter

, 02 2017 . 11:44 +
Nautics889 11:44

ip- Python , Tkinter

, Python , , UPD-, , .

ip-. . IDLE, , Eclipse PyDev.

?


IPv4 ( 0 255), . ip- . , , ip-, - . . .

, , , , .

generator()


, , generator(), amount:

def generator(amount):
    for n in range(amount):
        #  ,   4   
        a = randint(0,255)
        b = randint(0,255)
        c = randint(0,255)
        d = randint(0,255)
        #    
        f = open('ip-addresses.txt', 'a', encoding='utf-8')
        f.write(str(a)+'.'+str(b)+'.'+str(c)+'.'+str(d)+'\n')
        f.close()
    #           ?
    print('Success!')

for, while'a. random ( from random import randint, ).

GUI Tkinter


, , , , , . Tkinter.
.

( Entry), ( Button), , , , :

from tkinter import *
#  
root = Tk()

label1=Label(root, text=" ip-")
label1.grid()

#  Frame,     
frame = Frame(root)
frame.grid()

label2=Label(frame, text=':')
label2.grid(row=1,column=1)
#   
entry_amount = Entry(frame, width=4, borderwidth=5)
entry_amount.grid(row=1,column=2)
# 
button1 = Button(frame, text="")
button1.grid(row=1, column=3, padx=(10,0))
#  
output = Text(frame, bg="lightblue", font="Arial 9", width=45, height=3)
output.grid(row=2, columnspan=8)

root.mainloop()

grid, . :

image


, , , , generator. , , . try-except:

def handler():
    try:
        #  .get()
        amount = int(entry_amount.get())
        generator(amount)
    except ValueError:
        notif("  ")

#  ,      
def notif(value):
    output.delete("0.0","end") #    
    output.insert("0.0",value)

def notif(value), -, , . button1 command=handler ( ).

:

button1 = Button(frame, text="", command=handler)

command from distutils import command . , , .



, ? def delete():

def delete():
    try:
        remove('ip-addresses.txt')
        inserter(" ip-addresses.txt  ")
    except:
        inserter("   ")

, ( ). , delete:

button2 = Button(frame, text=" ", command=delete)
button2.grid(row=1, column=4, padx=(10,0))

grid , frame. from os import remove. , .

-


ip 500 , , for. , , -.

: Tkinter . Tkinter', for, , , , 10, 100 . ( , Tkinter 99%). , - , , . ( ), . : ; .

generator:

def generator(amount, port=''):
    for n in range(amount):
        a = randint(0,255)
        b = randint(0,255)
        c = randint(0,255)
        d = randint(0,255)
        f = open('ip-addresses.txt', 'a', encoding='utf-8')
        f.write(str(a)+'.'+str(b)+'.'+str(c)+'.'+str(d)+port+'\n')
        f.close()
        #      prc  ,  n   amount  ,  amount  100%
        prc = int(n//(amount/100))
        print(str(prc)+'%')
    print('Success!')
    
    #   GUI     txt-
    notif("IP-     \nip-addresses.txt")

, 500, , . :

image

. ? :

def generator(amount, port=''):
    prc_bfr=0 #      
    for n in range(amount):
        a = randint(0,255)
        b = randint(0,255)
        c = randint(0,255)
        d = randint(0,255)
        f = open('ip-addresses.txt', 'a', encoding='utf-8')
        f.write(str(a)+'.'+str(b)+'.'+str(c)+'.'+str(d)+port+'\n')
        f.close()
        prc = int(n//(amount/100))
        #,      prc 
        if(prc!=prc_bfr):
            print(str(prc)+'%')
        prc_bfr = prc        
    print('Success!')

    notif("IP-     \nip-addresses.txt")

! -, , .

ip-


ip- 8080, ? . GUI: Radiobutton, : . Entry :

label2 = Label(frame, text=' :')
label2.grid(row=2,column=1)
entry_port = Entry(frame, width=4, borderwidth=5, state=DISABLED)
entry_port.grid(row=2,column=2)
# var1    radiobutton'
var1 = IntVar()
check_port1 = Radiobutton(frame, text=' ', variable=var1, value=1, command=lock)
check_port1.grid(row=2,column=3)
check_port2 = Radiobutton(frame, text=" ", variable=var1, value=0, command=lock)
check_port2.grid(row=2,column=4)

entry_port . check_port lock() , / . lock:
def lock():
    #  check_port2:
    if var1.get() == 1:
        entry_port.configure(state=NORMAL)
    #  check_port1:
    elif var1.get() == 0:
        entry_port.configure(state=DISABLED)

GUI :

image

- handler if-else, ( var1):

def handler():
    try:
        amount = int(entry_amount.get())
        #  
        if var1.get() == 1:
            port = ':'+str(int(entry_port.get())) #    int    ,    str,     
            generator(amount, port)
        else:
            #      
            generator(amount)
    except ValueError:
        notif("  /")

, - . :

def generator(amount, port='')


port , , . :

f.write(str(a)+'.'+str(b)+'.'+str(c)+'.'+str(d)+port+'\n')

, :

import tkinter
import random
from tkinter import *
from random import randint
from os import remove
from distutils import command

print('Logs terminal:')

def generator(amount, port=''):
    prc_bfr=0
    for n in range(amount):
        a = randint(0,255)
        b = randint(0,255)
        c = randint(0,255)
        d = randint(0,255)
        f = open('ip-addresses.txt', 'a', encoding='utf-8')
        f.write(str(a)+'.'+str(b)+'.'+str(c)+'.'+str(d)+port+'\n')
        f.close()
        
        prc = int(n//(amount/100))
        
        if(prc!=prc_bfr):
            print(str(prc)+'%')
        prc_bfr = prc        
    print('Success!')

    notif("IP-     \nip-addresses.txt")
    
def notif(value):
    output.delete("0.0","end")
    output.insert("0.0",value)

def handler():
    try:
        amount = int(entry_amount.get())
        if var1.get() == 1:
            port = ':'+str(int(entry_port.get()))
            generator(amount, port)
        else:
            generator(amount)
    except ValueError:
        notif("  /")

def delete():
    try:
        remove('ip-addresses.txt')
        notif(" ip-addresses.txt  ")
    except:
        notif("   ")

def lock():
    if var1.get() == 1:
        entry_port.configure(state=NORMAL)
    elif var1.get() == 0:
        entry_port.configure(state=DISABLED)
        
root = Tk()

label1=Label(root, text=" ip-")
label1.grid()

frame = Frame(root)
frame.grid()

label2=Label(frame, text=':')
label2.grid(row=1,column=1)

entry_amount = Entry(frame, width=4, borderwidth=5)
entry_amount.grid(row=1,column=2)


button1 = Button(frame, text="", command=handler)
button1.grid(row=1, column=3, padx=(10,0))

button2 = Button(frame, text=" ", command=delete)
button2.grid(row=1, column=4, padx=(10,0))

label2=Label(frame, text=' :')
label2.grid(row=2,column=1)

entry_port = Entry(frame, width=4, borderwidth=5, state=DISABLED)
entry_port.grid(row=2,column=2)

var1 = IntVar()

check_port1 = Radiobutton(frame, text=' ', variable = var1, value=1, command=lock)
check_port1.grid(row=2,column=3)
check_port2 = Radiobutton(frame, text=" ", variable = var1, value=0, command=lock)
check_port2.grid(row=2,column=4)

output = Text(frame, bg="lightblue", font="Arial 9", width=45, height=3)
output.grid(row=3, columnspan=8)

root.mainloop()

. , , , , , - -., Python .
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/339124/

:  

: [1] []
 

:
: 

: ( )

:

  URL