Programı Tkinter ile arayüz programlamayı öğrenmek için yazdım. İki Python sürümünde de sorunsuz çalışıyor. Yeni başlayanlara style, grid, text ve progressbar widget'leri ile ilgili fikir vermesi amacıyla paylaşıyorum. Programı SEO amaçlı kullanacak olanlar Linux pakedini indirip herhangi bir kurulum yapmadan çalıştırabilirler.

İndirme linki: Github


#!/usr/bin/env python
# -*- coding: UTF-8 -*-

from __future__ import print_function

import sys
python_version = int(sys.version[0])

if python_version == 2:
import Tkinter as tkinter
import ttk

elif int(sys.version[0]) > 2:
import tkinter
from tkinter import ttk


__author__ = {
'name': 'Ertuğrul',
'mail': 'mail@rastignac.org',
}


import difflib

def get_similarity_ratio(a, b):
similarity = difflib.SequenceMatcher(a = a.lower(), b = b.lower())
return similarity.ratio()


class Application(ttk.Frame):

def __init__(self, parent):
ttk.Frame.__init__(self, parent)
self.parent = parent
self.initUI()

def initUI(self):
self.parent.title('Seqcheck')
self.pack(fill = tkinter.BOTH, expand = 1)

self.rowconfigure(0, weight = 0)
self.columnconfigure(0, weight = 4)
self.rowconfigure(1, weight = 1)
self.columnconfigure(1, weight = 4)
self.rowconfigure(2, weight = 1)
self.columnconfigure(2, weight = 4)

self.style = ttk.Style()
self.style.theme_use('clam')

self.text1_label = ttk.Label(self, text = 'Text 1')
self.text1_label.grid(row = 0, column = 0, pady = 3, padx = 6,
sticky = tkinter.E + tkinter.W + tkinter.S + tkinter.N)

self.text1 = tkinter.Text(self)
self.text1.grid(row = 1, column = 0, columnspan = 4, rowspan = 4, padx = 5,
sticky = tkinter.E + tkinter.W + tkinter.S + tkinter.N)

self.text2_label = ttk.Label(self, text = 'Text 2')
self.text2_label.grid(row = 0, column = 4, pady = 3, padx = 6,
sticky = tkinter.E + tkinter.W + tkinter.S + tkinter.N)

self.text2 = tkinter.Text(self)
self.text2.grid(row = 1, column = 4, columnspan = 4, rowspan = 4,
sticky = tkinter.E + tkinter.W + tkinter.S + tkinter.N)

self.style.configure('TProgressbar', foreground = 'green', background = 'green')
self.similarity_ratio_bar = ttk.Progressbar(self, orient = tkinter.HORIZONTAL, mode = 'indeterminate',
maximum = 100)
self.similarity_ratio_bar.grid(row = 8, column = 4, columnspan = 10, pady = 10,
sticky = tkinter.E + tkinter.W + tkinter.S + tkinter.N)

self.similarity_ratio_label = ttk.Label(self)
self.similarity_ratio_label.grid(row = 9, column = 4, columnspan = 10)

self.check_button = tkinter.Button(self, text = 'Analysis', command = self.check_button_on_click)
self.check_button.grid(row = 8, column = 0, columnspan = 4, pady = 10, padx = 6,
sticky = tkinter.E + tkinter.W + tkinter.S + tkinter.N)

def check_button_on_click(self):
self.show_similarity_ratio()

def show_similarity_ratio(self):
self.similarity_ratio_bar.stop()
seq_ratio = get_similarity_ratio(self.text1.get(0.0, tkinter.END), self.text2.get(0.0, tkinter.END))
print('Sequence ratio: {0}'.format(seq_ratio))
ratio = int((seq_ratio * 100.0) / 1.0)
print('Similarity ratio: {0}'.format(ratio))
if ratio <= 22:
self.style.configure('TProgressbar', foreground = 'green', background = 'green')
elif ratio <= 44:
self.style.configure('TProgressbar', foreground = 'blue', background = 'blue')
elif ratio <= 77:
self.style.configure('TProgressbar', foreground = 'orange', background = 'orange')
elif ratio <= 88:
self.style.configure('TProgressbar', foreground = 'purple', background = 'purple')
else:
self.style.configure('TProgressbar', foreground = 'red', background = 'red')
self.similarity_ratio_bar.step(ratio)
self.similarity_ratio_label['text'] = 'Ratio: {0}%\t\tSequence ratio: {1}'.format(ratio, seq_ratio)


def run():
root = tkinter.Tk()
try:
icon = tkinter.PhotoImage(file = 'icon.png')
# http://www.iconarchive.com/show/robots-icons-by-proycontec/robot-documents-icon.html
root.tk.call('wm', 'iconphoto', root._w, icon)
except:
pass
root.attributes('-zoomed', True)
application = Application(root)
root.mainloop()


if __name__ == '__main__':
run()