Aug-31-2020, 08:54 PM
I have two files with similar coding in each and I want to send data from one file to the other by calling it's function.
I want the result to be a Tkinter window and a shell window generated from each file.
By way of an example, I have created First.py and Second.py, with Second.py input to First.py.
Running First.py starts a counter and after a few seconds the function in Seond.py is called.
At this point I expected the Second.py Tkinter and shell windows to open.
Unfortunately what happens is that Second.py overwrites both the First.py Tkinter and shell windows
Can anyone please explain how to run both Tkinter and shell windows?
The coding is as below (note that it is an example to illustrate the problem of running two independent but linked files. Note also that the files run perfectly if run separately with the Function in Second.py disabled).
Many thanks
Astrikor
First.py:
I want the result to be a Tkinter window and a shell window generated from each file.
By way of an example, I have created First.py and Second.py, with Second.py input to First.py.
Running First.py starts a counter and after a few seconds the function in Seond.py is called.
At this point I expected the Second.py Tkinter and shell windows to open.
Unfortunately what happens is that Second.py overwrites both the First.py Tkinter and shell windows
Can anyone please explain how to run both Tkinter and shell windows?
The coding is as below (note that it is an example to illustrate the problem of running two independent but linked files. Note also that the files run perfectly if run separately with the Function in Second.py disabled).
Many thanks
Astrikor
First.py:
import Second from tkinter import * import time from datetime import datetime Count = 0 Posted = False #tkinter window setup: root = Tk() var = StringVar() var.set('') Label(root,textvariable = var, font=("ComicSans", 20)).pack() while True: Count=Count+1 LatestCount= Count ElapsedCount = (LatestCount)/5 if ElapsedCount == int(ElapsedCount) and Posted == True: Posted = False if Posted == False: Posted = True time.sleep(2) print("First ",Count, " ", LatestCount, " ", int(ElapsedCount)) p = "First ",datetime.now().strftime("%a %T") , " C:",str(Count), " EC:",str(ElapsedCount) separator = ' ' p= separator.join(p) var.set(p) root.update() if ElapsedCount == 5: Posted = True Second.OpenSecond(Posted,Count,ElapsedCount)Second.py:
from tkinter import * import time from datetime import datetime #tkinter window setup: Posted = True Count = 0 ElapsedCount=0 root = Tk() var = StringVar() var.set('') Label(root,textvariable = var, font=("ComicSans", 20)).pack() p = "Second ",datetime.now().strftime("%a %T") , " C:",str(Count) separator = ' ' p= separator.join(p) var.set(p) root.update() #if Count >=0:# use this line and inhibit the next line to run Second.py independently def OpenSecond(Posted,Count,ElapsedCount): Posted = Posted FirstCount = Count ElapsedCount = ElapsedCount while True: Count=Count+1 LatestCount= Count ElapsedCount = (LatestCount)/10 if ElapsedCount == int(ElapsedCount) and Posted == True: Posted = False if Posted == False: Posted = True time.sleep(2) print("FirstCount:", FirstCount,"Second Count:",Count, " ", int(ElapsedCount)) p = "Second ",datetime.now().strftime("%a %T") , " C:",str(Count), " EC:",str(ElapsedCount) separator = ' ' p= separator.join(p) var.set(p) root.update()