0

hi, is there any way to restart Tkinter program while running.
I would like to put some button that will when pressed put everything as it was in moment I started program

thx

3
Contributors
6
Replies
10
Views
5 Years
Discussion Span
Last Post by woooee
0

I do not understand, you can not have tkinter program without starting mainloop.

Edited by pyTony: n/a

0

You would have to store all of the initial values and change the values back when the button in pressed. Or, generally you use a class to run a Tkinter application so you can destroy the class instance and create it again. Some example code would help us help you as we don't know what "everything" in "put everything as it was in moment I started program" means.

Edited by woooee: n/a

0

here is a little cut from code.
I would like to have button that will put everything like I just started program

import tkinter as tk
import random
from functools import partial
from math import sqrt
popis = []
gotove=[] 
igrace=[] 
kartica = []
pr=[False]
kontrola=[True] 
igrac=[False]
okrenute= [0,0]
p=[0,0] 
b = 0
v=int(4) 
popis = 2 * [x for x in range(v//2)] 

def kraj():
    root.destroy()
    kraj= tk.Tk(padx=170,pady=70)
    kraj.title("Kraj")
    tk.Button(kraj, text = 'reset', command =????).grid(row=0,column=0)

def vrati_karirano(n):
    print ('some commands')
    if igrace == []:
        kraj()
        
    

def klik(n):
    kartica[n].config(image = s[popis[n]])
    
 
    if pr[0]:
        if n!=okrenute[0]:
            okrenute[1]=n    
            for i in range (v):
                kartica[i].config(state=tk.DISABLED)
            kartica[okrenute[0]].config(state=tk.NORMAL)
            kartica[okrenute[1]].config(state=tk.NORMAL)
            kartica[n].after(700, vrati_karirano, n)
            kontrola[0]=False
            pr[0]=False
    elif kontrola[0]:
        okrenute[0]=n
        pr[0]=True

root = tk.Tk()
frame1 = tk.Frame(root)
frame1.pack(side = tk.TOP, fill = tk.X)


karirano = tk.PhotoImage(file="kari.GIF")
s = [tk.PhotoImage(file = "{}.GIF".format(i+1)) for i in range(9)] 

for i in range(int(sqrt(v))):
    for j in range(int(sqrt(v))):
        gumb = tk.Button(frame1, image = karirano,command = partial(klik, b))
        gumb.grid(row = i, column = j)
        kartica.append(gumb)
        b += 1

root.mainloop()

Edited by Vkitor: n/a

0

Since the only difference is the image on the button, you would reset the image for each button in "gumb" to "karirano".

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.