tkinter - Setting a row limit for python code within for loop? -
question: how alter tkinter.label
's row once number of rows have been reached within for
loop?
code:
import tkinter import sys fractions import gcd def func(event): x = int(e1.get()) # max number result = [] in range(1, x): # loops each value in range of x b in range(a, x): c in range(b, x): if a**2 + b**2 == c**2 , gcd(a, b) == 1: # if primitive pyth triple, append result result += ['[',a,',',b,',',c,']'] # add group of triples list l = tkinter.message(root, text=result).grid(ipadx=5, ipady=5, sticky='w''e') # display each group of triples root l0 = tkinter.label(root, text="non-primitive , primitive triples").grid(ipadx=5, ipady=5, sticky='w''e') root.bind('<return>', close) # hit enter exit, temp debugging, reassign button later def close(event): # close program, define parameter event allow binding tkinter.sys.exit(0) sys.exit(0) root = tkinter.tk() # establish main gui root.title('generator') e1 = tkinter.entry(root) assert isinstance(e1, object) # method i've found allow entry().grid() e1.grid(ipadx=5, ipady=5, sticky='w''e') root.bind('<return>', func) # bind enter, cleaner , quicker button root.mainloop()
so, if have window displays
[#,#,#]
[#,#,#]
[#,#,#]
[#,#,#]
how change to, if want row limit four(starting on second row in first column because of entry widget, second column have 1 more first column, , remain constant each successive column), this:
entry.....[#,#,#]
[#,#,#]....[#,#,#]
[#,#,#]....[#,#,#]
[#,#,#]....[#,#,#]
i'm wanting l = tkinter.message(root, text=result).grid(ipadx=5, ipady=5, sticky='w''e') # display each group of triples root
in for
loop's if
statement, , change l = tkinter.label(root, text=('[',a,',',b,',',c,']')).grid(ipadx=5, ipady=5, sticky='w''e') # display each group of triples root
update
i fixed code code on here:
import tkinter import sys fractions import gcd def func(event): x = int(e1.get()) # max number row = 0 column = 0 count = 0 in range(1, x): # loops each value in range of x b in range(a, x): c in range(b, x): if a**2 + b**2 == c**2 , gcd(a, b) == 1: # if primitive pyth triple, print row += 1 l = tkinter.label(root, text=('[',a,',',b,',',c,']')) assert isinstance(l, object) l.grid(row=row, column=column, ipadx=5, ipady=5, sticky='w''e') # display each group of triples root root.title('primitive triples') if count > 1: l.destroy() if row == 7: column += 1 row -= 8 def close(): # close program tkinter.sys.exit(0) sys.exit(0) root = tkinter.tk() # establish main gui root.title('generator') e1 = tkinter.entry(root) assert isinstance(e1, object) # method i've found allow entry().grid() e1.grid(ipadx=5, ipady=5, sticky='w''e') root.bind('<return>', func) # bind enter, cleaner , quicker button root.mainloop()
just grid entry in row 0, column 0, first button in row 0, column 1, second button in row 1, column 0, etc. what's problem?
Comments
Post a Comment