Python Forum
[Tkinter] How to show text in window?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] How to show text in window?
#1
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)
Reply
#2
The code shown doesn't do anything.
Lots of unused imports.
Reply
#3
(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?
Reply
#4
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()
Reply
#5
Thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 343 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  Transparent window background, but not text on it muzicman0 7 2,734 Feb-02-2024, 01:28 AM
Last Post: Joically
  [PyQt] Hover over highlighted text and open popup window DrakeSoft 2 1,448 Oct-29-2022, 04:30 PM
Last Post: DrakeSoft
  tkinter window and turtle window error 1885 3 6,624 Nov-02-2019, 12:18 PM
Last Post: 1885
  [Tkinter] Text window not properly sized smabubakkar 1 1,891 Jun-16-2019, 08:55 AM
Last Post: Yoriz
  [PyQt] Can't show PyQt5 mediaPlayer in window DecaK 1 5,335 Sep-15-2018, 09:54 AM
Last Post: Axel_Erfurt
  update a variable in parent window after closing its toplevel window gray 5 8,976 Mar-20-2017, 10:35 PM
Last Post: Larz60+
  Show second window using classes iFunKtion 2 3,712 Feb-10-2017, 12:50 PM
Last Post: iFunKtion
  Show GPG keys in pyqt5 window Fred Barclay 1 4,532 Oct-24-2016, 07:09 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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