Question

Attached is an incomplete Python template file. button_get4_Q.py Download this file and complete it to solve the following pr

0 0
Add a comment Improve this question Transcribed image text
Answer #1

input , output screen shots are provided and simple comments are included for explanations. Please feel free to make any changes if required.

Thank You.

Source code:

import tkinter as tk
class gui:
def __init__(self,m):
self.mn = m #Creates window
self.mn.title("Get4") #sets window title
#Created a text area with font size and using width and height attribs
self.t1 = tk.Text(m,font=(32),width=14,height = 2)
self.t1.grid(row=0,column=0,columnspan=5, pady=5)
#created five buttons for five numbers and arranged them using grid
self.b1=tk.Button(m,text="1",command=lambda:self.ins("1"))
self.b1.grid(row=1,column=0,padx=5, pady=5)
self.b2=tk.Button(m,text="2",command=lambda:self.ins("2"))
self.b2.grid(row=1,column=1,padx=5, pady=5)
self.b3=tk.Button(m,text="3",command=lambda:self.ins("3"))
self.b3.grid(row=1,column=2,padx=5, pady=5)
self.b4=tk.Button(m,text="4",command=lambda:self.ins("4"))
self.b4.grid(row=1,column=3,padx=5, pady=5)
self.b5=tk.Button(m,text="5",command=lambda:self.ins("5"))
self.b5.grid(row=1,column=4,padx=5, pady=5)
#One more button for reset option
self.b6=tk.Button(m,text="RESET",command=self.reset)
self.b6.grid(row=2,column=0,columnspan=5,padx=5, pady=5)
#function for five buttons
def ins(self,val):
v = self.t1.get('1.0','end-1c')
if len(v)<4:
self.t1.insert(tk.END,val)
#reset button function
def reset(self):
self.t1.delete('1.0',tk.END)

root=tk.Tk()
gui = gui(root)
root.mainloop()

import tkinter as tk class gui: def __init__(self,m) : self.mn = m #Creates window self.mn.title(Get4) #sets window title #
output:

4321 RESET

Add a comment
Know the answer?
Add Answer to:
Attached is an incomplete Python template file. button_get4_Q.py Download this file and complete it to solve...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT