PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 18, 2022

[FIXED] how to get an output message from tkinter?

 August 18, 2022     output, python, tkinter     No comments   

Issue

I'm trying to make a quiz app and I have written the following code which is incomplete I am trying to get an output message from the app which gives the answer which the student has written it seems funny but i will do some more stuff on it too. the output I want should be something like this: the client enters 12 the app shows another box which says your answer is 12 but in this example it is being done for a single answer and it should be performable for more questions too.

import tkinter as tk
from tkinter import *
import math
import random
window=tk.Tk()
def question():
  window=tk.Tk()
  q1=tk.Label(window, text="enter your question").grid(row=1, column=1)
  e1=tk.Entry(window, text="the number of your answer ").grid(row=2, column=1)
  b1=tk.Button(window, text="exit", command=window.destroy).grid(row=3, column=1)
  window.mainloop()   

after your helps I have changed my code to this but still have prolems getting a message box or something like that. the updated code is as follows. now the problem is that as soon as I run the code the empty message box opens and does not wait for me to enter some value into the entry

def question():
  window=tk.Tk()
  q1=tk.Label(window, text="enter your question")
  e1=tk.Entry(window, text="the number of your answer ")
  b1=tk.Button(window, text="exit", command=window.destroy)
  q1.grid(row=1, column=1)
  e1.grid(row=2, column=1)
  b1.grid(row=3, column=1)
  e1_num=e1.get()
  while e1_num==None:
     pass
  else:
     messagebox.showinfo(e1_num)
  mainloop()

Solution

You could use e1.insert('0', 'subject') to insert something into the entry. You can also replace 'subject' with a variable. To delete the contents of the entry you can use e1.delete(0,END)

You can get the information from the Entry (e1) and store in it a variable like so: e1_num = e1.get()

I hope this helps you :D

Solution to your problem:

from tkinter import *
import tkinter as tk

def question():
    window=tk.Tk()
    window.geometry('200x125')
    window.title('Test')

    q1=tk.Label(window, text="Enter your question")
    e1=tk.Entry(window)
    e2=tk.Entry(window)
    b1=tk.Button(window, text="Exit", command=window.destroy)


    def Enter():
        e1_num = e1.get()
        e2.insert('0', e1_num)

    q1.pack()
    e1.pack()
    b2=Button(window, text='Enter', command=Enter)
    b2.pack()
    e2.pack()
    b1.pack()

    window.mainloop()

question()

What it will look like:

enter image description here



Answered By - some_user_3
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing