Feb-20-2018, 06:33 PM
(This post was last modified: Feb-20-2018, 06:33 PM by TollyThaWally.)
I am trying to make a program in Tkinter where you can press a button and it will add it to a list. I want to align the buttons with **No** text in the box **At All**. I want them in 6 rows of 6, then the 7th row with two in the center. Do you know how I can do this?
My Current Code Is:
N.B: I would like to avoid classes if possible, don't worry if it can't be done without.
My Current Code Is:
from tkinter import * result = [] def printa(): result.append('a') def printb(): result.append('b') def printc(): result.append('c') def printd(): result.append('d') def printe(): result.append('e') def printf(): result.append('f') def printg(): result.append('g') def printh(): result.append('h') def printi(): result.append('i') def printj(): result.append('j') def printk(): result.append('k') def printl(): result.append('l') def printm(): result.append('m') def printn(): result.append('n') def printo(): result.append('o') def printp(): result.append('p') def printq(): result.append('q') def printr(): result.append('r') def prints(): result.append('s') def printt(): result.append('t') def printu(): result.append('u') def printv(): result.append('v') def printw(): result.append('w') def printx(): result.append('x') def printy(): result.append('y') def printz(): result.append('z') def printspace(): result.append('space') def printperiod(): result.append('period') def print0(): result.append('0') def print1(): result.append('1') def print2(): result.append('2') def print3(): result.append('3') def print4(): result.append('4') def print5(): result.append('5') def print6(): result.append('6') def print7(): result.append('7') def print8(): result.append('8') def print9(): result.append('9') def printall(): print(''.join(result)) def clear(): result = [] root=Tk() ba=Button(root,command=printa) bb=Button(root,command=printb) bc=Button(root,command=printc) bd=Button(root,command=printd) be=Button(root,command=printe) bf=Button(root,command=printf) bg=Button(root,command=printg) bh=Button(root,command=printh) bi=Button(root,command=printi) bj=Button(root,command=printj) bk=Button(root,command=printk) bl=Button(root,command=printl) bm=Button(root,command=printm) bn=Button(root,command=printn) bo=Button(root,command=printo) bp=Button(root,command=printp) bq=Button(root,command=printq) br=Button(root,command=printr) bs=Button(root,command=prints) bt=Button(root,command=printt) bu=Button(root,command=printu) bv=Button(root,command=printv) bw=Button(root,command=printw) bx=Button(root,command=printx) by=Button(root,command=printy) bz=Button(root,command=printz) bspace=Button(root,command=printspace) bperiod=Button(root,command=printperiod) b0=Button(root,command=print0) b1=Button(root,command=print1) b2=Button(root,command=print2) b3=Button(root,command=print3) b4=Button(root,command=print4) b5=Button(root,command=print5) b6=Button(root,command=print6) b7=Button(root,command=print7) b8=Button(root,command=print8) b9=Button(root,command=print9) ok=Button(root,text='Print Result',command=printall) clear=Button(root,text='Clear',command=clear) photoa=PhotoImage(file='Symbols\\a.png') photob=PhotoImage(file='Symbols\\b.png') photoc=PhotoImage(file='Symbols\\c.png') photod=PhotoImage(file='Symbols\\d.png') photoe=PhotoImage(file='Symbols\\e.png') photof=PhotoImage(file='Symbols\\f.png') photog=PhotoImage(file='Symbols\\g.png') photoh=PhotoImage(file='Symbols\\h.png') photoi=PhotoImage(file='Symbols\\i.png') photoj=PhotoImage(file='Symbols\\j.png') photok=PhotoImage(file='Symbols\\k.png') photol=PhotoImage(file='Symbols\\l.png') photom=PhotoImage(file='Symbols\\m.png') photon=PhotoImage(file='Symbols\\n.png') photoo=PhotoImage(file='Symbols\\o.png') photop=PhotoImage(file='Symbols\\p.png') photoq=PhotoImage(file='Symbols\\q.png') photor=PhotoImage(file='Symbols\\r.png') photos=PhotoImage(file='Symbols\\s.png') photot=PhotoImage(file='Symbols\\t.png') photou=PhotoImage(file='Symbols\\u.png') photov=PhotoImage(file='Symbols\\v.png') photow=PhotoImage(file='Symbols\\w.png') photox=PhotoImage(file='Symbols\\x.png') photoy=PhotoImage(file='Symbols\\y.png') photoz=PhotoImage(file='Symbols\\z.png') photospace=PhotoImage(file='Symbols\\space.png') photoperiod=PhotoImage(file='Symbols\\period.png') photo0=PhotoImage(file='Symbols\\0.png') photo1=PhotoImage(file='Symbols\\1.png') photo2=PhotoImage(file='Symbols\\2.png') photo3=PhotoImage(file='Symbols\\3.png') photo4=PhotoImage(file='Symbols\\4.png') photo5=PhotoImage(file='Symbols\\5.png') photo6=PhotoImage(file='Symbols\\6.png') photo7=PhotoImage(file='Symbols\\7.png') photo8=PhotoImage(file='Symbols\\8.png') photo9=PhotoImage(file='Symbols\\9.png') ba.config(image=photoa) bb.config(image=photob) bc.config(image=photoc) bd.config(image=photod) be.config(image=photoe) bf.config(image=photof) bg.config(image=photog) bh.config(image=photoh) bi.config(image=photoi) bj.config(image=photoj) bk.config(image=photok) bl.config(image=photol) bm.config(image=photom) bn.config(image=photon) bo.config(image=photoo) bp.config(image=photop) bq.config(image=photoq) br.config(image=photor) bs.config(image=photos) bt.config(image=photot) bu.config(image=photou) bv.config(image=photov) bw.config(image=photow) bx.config(image=photox) by.config(image=photoy) bz.config(image=photoz) bspace.config(image=photospace) bperiod.config(image=photoperiod) b0.config(image=photo0) b1.config(image=photo1) b2.config(image=photo2) b3.config(image=photo3) b4.config(image=photo4) b5.config(image=photo5) b6.config(image=photo6) b7.config(image=photo7) b8.config(image=photo8) b9.config(image=photo9) ba.pack() bb.pack() bc.pack() bd.pack() be.pack() bf.pack() bg.pack() bh.pack() bi.pack() bj.pack() bk.pack() bl.pack() bm.pack() bn.pack() bo.pack() bp.pack() bq.pack() br.pack() bs.pack() bt.pack() bu.pack() bv.pack() bw.pack() bx.pack() by.pack() bz.pack() bspace.pack() bperiod.pack() b0.pack() b1.pack() b2.pack() b3.pack() b4.pack() b5.pack() b6.pack() b7.pack() b8.pack() b9.pack() ok.pack() clear.pack() root.mainloop()And every button just appears in one huge list going down.
N.B: I would like to avoid classes if possible, don't worry if it can't be done without.