Output result in a new Window - python

Basically, I have a root window that has a couple of buttons that runs different Python code, and it outputs the result into the console.
Is there a way to display the output into a new window (pop-up window) once the user clicks the button?

You could make a message box by doing
The Imports:
import Tkinter
from Tkinter import *
import tkMessageBox
import ttk
Heres the Code:
window = Tkinter.Tk()
window.wm_withdraw()
#centre screen message
window.geometry("1x1+"+str(window.winfo_screenwidth()/2)
+"+"+str(window.winfo_screenheight()/2))
tkMessageBox.showinfo(title=" ", message=" ")

Related

How to display my console logs on my tkinter window?

from tkinter import Tk
from tqdm import tqdm
root = Tk()
root.geometry('300x300')
root.mainloop()
for i in tqdm(range(1000)):
pass
Can it see the process bar inside m tkinter window?

print weather update in tkinter Gui interface

I want to print the condition weather on tkinter gui interface.So I wrote this code....
import tkinter as tk
from tkinter import *
from weather import Weather,Unit
win=tk.Tk()
weather = Weather(unit=Unit.CELSIUS)
location=weather.lookup_by_location('Dhaka')
condition=location.condition
label=Label(text=condition)
label.pack()
win.mainloop()
But the output sample is...
But I want output that show condition like Sunny,Thunderstorm etc.
You've linked the object to a label, you need to call the text. condition.text
import tkinter as tk
from tkinter import *
from weather import Weather,Unit
win=tk.Tk()
weather = Weather(unit=Unit.CELSIUS)
location=weather.lookup_by_location('Dhaka')
condition=location.condition
label=Label(text=condition.text)
label.pack()
win.mainloop()

get output of the python code

I have ScrolledText in Tkiner application ,in which i am supposed to write the python code in it and i have one button,by pressing that i send those lines of code to InteractiveInterpreter().runcode("code as a string")
This runcode() method return the NoneType object and shows output on the cmd
but i want output in string format, i tried using exec() but it didn't work for me.There is some way to do that?
import Tkinter as tk
from Tkinter import *
from ScrolledText import *
from code import InteractiveInterpreter
interpreter = InteractiveInterpreter()
def go(event):
print(interpreter.runcode(textPad.get('1.0', END+'-1c')))
root = tk.Tk()
textPad = ScrolledText(root,width=100,height=100)
textPad.focus_set()
b2=tk.Button(root, text ="Run",width=34,height=3)
b2.pack()
b2.bind('<Button-1>', go)
textPad.pack()
root.mainloop()

python tkinter - get cursor in new window

I'd like to use the tab key in both showing of the following code:
from tkinter import *
main = Tk()
def pressButton():
main.destroy()
End=Button(main,text='Finished',width=15,command=pressButton).grid()
main.mainloop()
from tkinter import *
main = Tk()
def pressButton():
main.destroy()
End=Button(main,text='Finished',width=15,command=pressButton).grid()
main.mainloop()
first window works: i can press tab and space and it opens the second window; there i'm not able to "press button" by using tab and space, because the cursor is in Python Shell.
How can I get the cursor in the second window?
As mention in that post "Tkinter main window focus", it is possible to force the focus to the main window.
Solution - add a call to the after() to focus_force().
from tkinter import *
main = Tk()
def pressButton():
main.destroy()
End=Button(main,text='Finished',width=15,command=pressButton).grid()
# call the focus_force() after the window is displayed
main.after(1, lambda: main.focus_force())
main.mainloop()

How to set a tkinter windows on top when running a slide app (e.g. Keynote)

I want to show some dynamic text in a window on top when playing a slide show in fullscreen mode. I use the OS X.
I had tried the method attributes("-topmost", 1). Not work...
Thanks
Here is my code:
# coding=utf-8
from tkinter import *
from tkinter import ttk
root = Tk()
root.title(u"弾幕")
root.attributes("-alpha", 0.3)
root.attributes("-topmost", 1)
root.mainloop()

Categories

Resources