Python Forum

Full Version: How to show text in window?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I am looking for help having the text that outputs on the Command Prompt to show on the black box on this program. Any ideas on how to make this happen?
import tkinter as tk
from tkinter import filedialog, Text
import os
import time
import numpy as np
import urllib3 
root=tk.Tk()                   
def forecast():
    print("My Forecast")
def models():
    print("Models selected. ")
canvas = tk.Canvas(root, height=480, width=640, bg='black')
canvas.pack()

frame = tk.Frame(root, bg='black')
frame.place(relwidth=0.6, relheight=0.6, relx=0.1, rely=0.1)
forecast = tk.Button(root, text="Forecasts", padx=2, pady=3, fg='white', bg="red", command = forecast)
forecast.pack()

models = tk.Button(root, text="Models", padx=2, pady=3, fg='white', bg="red", command = models)
models.pack()
Output:
Models selected. My Forecast
(Buttons also show as part of the GUI)
The code shown doesn't do anything.
Lots of unused imports.
(Jun-20-2020, 03:34 PM)Yoriz Wrote: [ -> ]The code shown doesn't do anything.
Lots of unused imports.
I tested it out and it shows buttons, I forgot the root.mainloop() at the end. Does this change anything?
import time
import tkinter as tk
from tkinter import Text, filedialog

root = tk.Tk()


def forecast():
    print("My Forecast")
    label['text'] = "My Forecast"


def models():
    print("Models selected. ")
    label['text'] = "Models selected. "


canvas = tk.Canvas(root, height=480, width=640, bg='black')
canvas.pack()

frame = tk.Frame(root, bg='black')
frame.place(relwidth=0.6, relheight=0.6, relx=0.1, rely=0.1)
label = tk.Label(frame, fg='white', bg='black')
label.pack()
forecast = tk.Button(root, text="Forecasts", padx=2, pady=3,
                     fg='white', bg="red", command=forecast)
forecast.pack()

models = tk.Button(root, text="Models", padx=2, pady=3,
                   fg='white', bg="red", command=models)
models.pack()

tk.mainloop()
Thank you!