Python Forum
Dual Tkinter windows and shells
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dual Tkinter windows and shells
#1
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:
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()
Reply


Messages In This Thread
Dual Tkinter windows and shells - by Astrikor - Aug-31-2020, 08:54 PM
RE: Dual Tkinter windows and shells - by deanhystad - Aug-31-2020, 09:27 PM
RE: Dual Tkinter windows and shells - by Astrikor - Sep-01-2020, 06:59 AM
RE: Dual Tkinter windows and shells - by deanhystad - Sep-01-2020, 02:27 PM
RE: Dual Tkinter windows and shells - by Astrikor - Sep-01-2020, 06:51 PM
RE: Dual Tkinter windows and shells - by deanhystad - Sep-01-2020, 08:20 PM
RE: Dual Tkinter windows and shells - by Astrikor - Sep-03-2020, 10:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter two windows instead of one jacksfrustration 7 970 Feb-08-2024, 06:18 PM
Last Post: deanhystad
  pass a variable between tkinter and toplevel windows janeik 10 2,534 Jan-24-2024, 06:44 AM
Last Post: Liliana
  Tkinter multiple windows in the same window tomro91 1 926 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  [Tkinter] DUAL WINDOWS... ATARI_LIVE 5 3,076 Sep-27-2020, 11:35 AM
Last Post: ATARI_LIVE
  Tkinter scaling windows conten to or with its size not working Detzi 5 4,560 Jan-12-2020, 12:42 PM
Last Post: Detzi
  How to close one of the windows in Tkinter scratchmyhead 3 4,868 Dec-21-2019, 06:48 PM
Last Post: pashaliski
  Using tkinter on Windows to launch python 3 scripts Mocap 1 2,778 Jul-17-2019, 05:16 AM
Last Post: Yoriz
  [Tkinter] Using tkinter and mutiprocess ok on windows, locks up on ubuntu? ice 3 2,745 May-29-2019, 08:44 AM
Last Post: ice
  Int Variables in different Tkinter windows only returning 0 harry76 3 4,206 May-26-2019, 10:24 AM
Last Post: Yoriz
  [Tkinter] Ignore windows scaling in tkinter Gangwick 2 4,502 Jul-23-2018, 02:41 PM
Last Post: Gangwick

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020