Reputation: 56
For some reason, when I try to run my code the GUI window turns up blank. The console does not show any error and the rest of the program runs smoothly. When I ran it separately, without the other code, it ran perfectly. I used to have the 'time' module too, but then I removed it as some said it might cause problems. Any help would be very much appreciated.
OS: Windows | Python Version: 3.8.4
Modules used:
os
webbrowser
random
requests
bs4
arrow
wikipediaapi
re
urllib
io
speech_recognition
pyaudio
cv2
pickle
tkinter.scrolledtext
PyQt5
tkinter
numpy
gtts
pyowm.owm
bs4
urllib.request
googletrans
console.utils
PIL
tzlocal
pygame
(I know that is a lot of modules)
GUI Code:
window = tk.Tk()
window.title("Ida")
window.configure(bg='black')
window.geometry("1500x800")
frame = tk.Frame(window)
frame.pack()
wid = 750
hei = 790
canvas = tk.Canvas(frame, bg="black", width = wid, height = hei)
canvas.config(highlightthickness=0)
canvas.pack()
logo = ImageTk.PhotoImage(file="Ida.png")
canvas.create_image(wid/2, hei/2, image=logo)
window.iconphoto(False, ImageTk.PhotoImage(file="Ida_icon.png"))
btn = tk.Button(window, text = 'The creator!', height = 2, width = 10,
bd = '5', bg="turquoise",
command = lambda : webbrowser.open("www.gigablitzonline.wordpress.com"))
# Set the position of button on the top of window.
btn.pack(side = 'left')
btn.place(x= 10, y= hei/2)
txt = scrolledtext.ScrolledText(frame, undo=True, wrap = tk.WORD)
txt['font'] = ('Calibri', '12')
txt.configure(height=6, bg = "black", fg = "white")
txt.pack(expand=True, fill='both')
txt.place(x = wid/2-250,y = 625, width = 500)
txt.configure(state = 'disabled')
input_box = scrolledtext.ScrolledText(frame, undo=True, wrap = tk.WORD)
input_box['font'] = ('Calibri', '12')
input_box.configure(height=3, bg = "black", fg = "white")
input_box.pack(expand=True, fill='both')
input_box.place(x = wid/2-250,y = 745, width = 500)
input_box.configure(state = 'disabled')
Upvotes: 0
Views: 4309
Reputation: 5339
I have created a compact working version from your GUI code. It doesn't contain serious defect so I guess the problem is not really in your GUI section.
The possible issues:
x.mainloop()
end of file. Or the place is not correct.mainloop()
(Eg.: Long for
loop)But you can see below my test code. Perhaps it can help you to fix your issue.
Code:
import tkinter as tk
import tkinter.scrolledtext as tkst
from PIL import ImageTk, Image
window = tk.Tk()
window.title("Ida")
window.configure(bg="black")
window.geometry("1500x800")
frame = tk.Frame(window)
frame.pack()
wid = 750
hei = 790
canvas = tk.Canvas(frame, bg="black", width=wid, height=hei)
canvas.config(highlightthickness=0)
canvas.pack()
load = Image.open("Ida.jpeg") # Open the picture
my_image = load.resize((500, 300)) # Resize picture to 300x300
logo = ImageTk.PhotoImage(my_image)
canvas.create_image(wid / 2, hei / 2, image=logo)
btn = tk.Button(
window,
text="The creator!",
height=2,
width=10,
bd="5",
bg="turquoise",
command=lambda: print("OK"),
)
# Set the position of button on the top of window.
btn.pack(side="left")
btn.place(x=10, y=hei / 2)
txt = tkst.ScrolledText(frame, undo=True, wrap=tk.WORD)
txt["font"] = ("Calibri", "12")
txt.configure(height=6, bg="black", fg="white")
txt.pack(expand=True, fill="both")
txt.place(x=wid / 2 - 250, y=625, width=500)
txt.configure(state="disabled")
input_box = tkst.ScrolledText(frame, undo=True, wrap=tk.WORD)
input_box["font"] = ("Calibri", "12")
input_box.configure(height=3, bg="black", fg="white")
input_box.pack(expand=True, fill="both")
input_box.place(x=wid / 2 - 250, y=745, width=500)
input_box.configure(state="disabled")
window.mainloop()
GUI:
Console output:
I have changed the callback function in the Button
widget to a simple print("OK")
>>> python3 test.py
OK
OK
OK
Upvotes: 0
Reputation: 472
I think you should finish your code off with window.mainloop()
or you can simply use mainloop
Upvotes: 1