Implement calculate and clear function

This commit is contained in:
Late Night Defender 2023-10-03 23:13:56 +07:00
parent 15f1940310
commit daa569d760
3 changed files with 71 additions and 9 deletions

View file

@ -52,7 +52,7 @@
(2,58,"GtkText",None,44,None,None,None,None,None),
(2,59,"GtkText",None,45,None,None,None,None,None),
(2,60,"GtkText",None,30,None,None,None,None,None),
(2,61,"GtkEntry","rank_output",30,None,None,None,1,None),
(2,61,"GtkEntry",None,30,None,None,None,1,None),
(2,62,"GtkEntry",None,36,None,None,None,1,None),
(2,63,"GtkEntry",None,37,None,None,None,1,None),
(2,64,"GtkEntry",None,38,None,None,None,1,None),
@ -74,9 +74,10 @@
(2,80,"GtkEntry",None,44,None,None,None,2,None),
(2,81,"GtkEntry",None,45,None,None,None,2,None),
(2,82,"GtkBox",None,26,None,None,None,1,None),
(2,83,"GtkButton",None,82,None,None,None,None,None),
(2,83,"GtkButton","clear_button",82,None,None,None,None,None),
(2,84,"GtkButton","calculate_button",82,None,None,None,1,None),
(2,85,"GtkTextBuffer","inputdata",25,None,None,None,-1,None)
(2,85,"GtkTextBuffer","inputdata",25,None,None,None,-1,None),
(2,86,"GtkEntryBuffer","rank_output",61,None,None,None,-1,None)
</object>
<object_property>
(2,1,"GtkWindow","default-height","600",None,None,None,None,None,None,None,None,None),
@ -207,6 +208,7 @@
(2,60,"GtkWidget","height-request","50",None,None,None,None,None,None,None,None,None),
(2,60,"GtkWidget","width-request","100",None,None,None,None,None,None,None,None,None),
(2,61,"GtkEditable","editable","False",None,None,None,None,None,None,None,None,None),
(2,61,"GtkEntry","buffer",None,None,None,None,None,86,None,None,None,None),
(2,61,"GtkWidget","height-request","40",None,None,None,None,None,None,None,None,None),
(2,61,"GtkWidget","margin-bottom","5",None,None,None,None,None,None,None,None,None),
(2,61,"GtkWidget","margin-end","5",None,None,None,None,None,None,None,None,None),

View file

@ -25,13 +25,70 @@ class CountWindow(Adw.ApplicationWindow):
__gtype_name__ = 'CountWindow'
calculate_button = Gtk.Template.Child()
clear_button = Gtk.Template.Child()
inputdata = Gtk.Template.Child()
rank_output = Gtk.Template.Child()
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.calculate_button.connect('clicked', self.on_clicked)
self.calculate_button.connect('clicked', self.calculate_clicked)
self.clear_button.connect('clicked', self.clear_clicked)
def on_clicked(self, btnobj):
userinput = self.inputdata.get_text(self.inputdata.get_start_iter(),self.inputdata.get_end_iter(),False)
print(userinput)
def clear_clicked(self, btnobj):
self.inputdata.set_text("",0)
def calculate_clicked(self, btnobj):
userInput = self.inputdata.get_text(self.inputdata.get_start_iter(),self.inputdata.get_end_iter(),False)
zero,one,two,three,four,five,six,seven,eight,nine=0,0,0,0,0,0,0,0,0,0
for i in userInput:
if i=="0":
zero+=1
elif i=="1":
one+=1
elif i=="2":
two+=1
elif i=="3":
three+=1
elif i=="4":
four+=1
elif i=="5":
five+=1
elif i=="6":
six+=1
elif i=="7":
seven+=1
elif i=="8":
eight+=1
elif i=="9":
nine+=1
print()
print("0 = ",zero)
print("1 = ",one)
print("2 = ",two)
print("3 = ",three)
print("4 = ",four)
print("5 = ",five)
print("6 = ",six)
print("7 = ",seven)
print("8 = ",eight)
print("9 = ",nine)
rank=[zero,one,two,three,four,five,six,seven,eight,nine]
rankNumber = ""
print()
print("Rank : ",end='')
for j in range(10):
most = -1
mostIndex = -1
for i in range(10):
if rank[i]>most:
most=rank[i]
mostIndex=i
rankNumber += str(mostIndex)
rank[mostIndex]=-1
print(rankNumber)
self.rank_output.set_text(rankNumber,-1)

View file

@ -496,7 +496,10 @@
</object>
</child>
<child>
<object class="GtkEntry" id="rank_output">
<object class="GtkEntry">
<property name="buffer">
<object class="GtkEntryBuffer" id="rank_output"/>
</property>
<property name="editable">False</property>
<property name="height-request">40</property>
<property name="margin-bottom">5</property>
@ -514,7 +517,7 @@
<property name="height-request">0</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkButton">
<object class="GtkButton" id="clear_button">
<property name="height-request">70</property>
<property name="label">ล้างข้อมูล</property>
<property name="margin-bottom">5</property>