Tkinter: how to open a Toplevel window from another script

Asked
Active3 hr before
Viewed126 times

4 Answers

scripttkintertoplevelwindow
90%

Running python -m tkinter from the command line should open a window demonstrating a simple Tk interface, letting you know that tkinter is properly installed on your system, and also showing what version of Tcl/Tk is installed, so you can read the Tcl/Tk documentation specific to that version,,These commands and their arguments will be passed to a C function in the _tkinter - note the underscore - extension module

Example_snippet/controller/utility/_script.js/ from tkinter import * from tki. . .
from tkinter
import *
from tkinter
import ttk
load more v
88%

How to keep the window focus on the new Toplevel() window in Tkinter?,How to center a window on the screen in Tkinter?,How to make a Tkinter window jump to the front?,In this example, we have created a button widget that will open the new window with a text label,

Example_snippet/controller/utility/_tkinter.js/ #Import tkinter library from t. . .
#Import tkinter library
from tkinter
import *
from tkinter
import ttk
#Create an instance of tkinter frame or window
win = Tk()
#Set the geometry of tkinter frame
win.geometry("750x250")
#Define a new function to open the window
def open_win():
   new = Toplevel(win)
new.geometry("750x250")
new.title("New Window")
#Create a Label in New window
Label(new, text = "Hey, Howdy?", font = ('Helvetica 17 bold')).pack(pady = 30)
#Create a label
Label(win, text = "Click the below button to Open a New Window", font = ('Helvetica 17 bold')).pack(pady = 30)
#Create a button to open a New Window
ttk.Button(win, text = "Open", command = open_win).pack()
win.mainloop()
72%

Second, assign the command of the Open a window button to the open_window() method in the App class,First, define a class Window that inherits from the Toplevel window, The Window will be closed once the Close button is clicked

Example_snippet/controller/utility/_tkinter.js/ .wp-block-code { border: 0; . . .
.wp - block - code {
      border: 0;
      padding: 0;
   }

   .wp - block - code > div {
      overflow: auto;
   }

   .shcb - language {
      border: 0;
      clip: rect(1 px, 1 px, 1 px, 1 px); -
      webkit - clip - path: inset(50 % );
      clip - path: inset(50 % );
      height: 1 px;
      margin: -1 px;
      overflow: hidden;
      padding: 0;
      position: absolute;
      width: 1 px;
      word - wrap: normal;
      word - break: normal;
   }

   .hljs {
      box - sizing: border - box;
   }

   .hljs.shcb - code - table {
      display: table;
      width: 100 % ;
   }

   .hljs.shcb - code - table > .shcb - loc {
      color: inherit;
      display: table - row;
      width: 100 % ;
   }

   .hljs.shcb - code - table.shcb - loc > span {
      display: table - cell;
   }

   .wp - block - code code.hljs: not(.shcb - wrap - lines) {
      white - space: pre;
   }

   .wp - block - code code.hljs.shcb - wrap - lines {
      white - space: pre - wrap;
   }

   .hljs.shcb - line - numbers {
      border - spacing: 0;
      counter - reset: line;
   }

   .hljs.shcb - line - numbers > .shcb - loc {
      counter - increment: line;
   }

   .hljs.shcb - line - numbers.shcb - loc > span {
      padding - left: 0.75 em;
   }

   .hljs.shcb - line - numbers.shcb - loc::before {
      border - right: 1 px solid #ddd;
      content: counter(line);
      display: table - cell;
      padding: 0 0.75 em;
      text - align: right; -
      webkit - user - select: none; -
      moz - user - select: none; -
      ms - user - select: none;
      user - select: none;
      white - space: nowrap;
      width: 1 % ;
   }
window = tk.Toplevel(root) Code language: Python(python)
load more v
65%

Connect and share knowledge within a single location that is structured and easy to search,, Why are other countries reacting negatively to Australia's decision to deploy nuclear submarines? ,If I put together the scripts (inserting the code of "script_two" in 'def sw()'), I get exactly what I want, but if I split them as showed, I get the problem

Example_snippet/controller/utility/_tkinter.js/ from tkinter import * import o. . .
from tkinter
import *
import os
main = Tk()
def sw():
   os.system("python3 ./script_two.py")
my_button = Button(main, text = "NEW", command = sw)
my_button.grid(row = 0, column = 0)
if__name__ = "__main__":
   main.mainloop()
load more v