0

I stuck on this one and i dont know how to get #Button1, 2 and 3 under Submit button in def callback:

also how get all collected data from Submit button in def callback: and paste into Msg.HTMLBody

import tkinter as tk
from tkinter import *
from tkinter import ttk
from tkinter.ttk import *
import win32com.client 

root = tk.Tk()
v = tk.IntVar()




# Name & Input
tk.Label(root, text="Full Name").grid(row=0, column = 0)
e1 = tk.Entry(root)
e1.grid(row=0, column = 1)


# Employer Number & Input
tk.Label(root, text="Employy Number").grid(row=1, column = 0)
e2 = tk.Entry(root)
e2.grid(row=1, column = 1)


# Question 1

tk.Label(root,text="Are you happy in your job?", justify = tk.LEFT, padx = 20).grid(row=4, column = 0)

#Button 1

tk.Radiobutton(root,text="Not happy",fg="red",padx = 200,variable=v, value=1).grid(row=5, column = 0)

#Button 2

tk.Radiobutton(root, text="Happy",fg="blue",padx = 20,variable=v,value=2).grid(row=5, column = 1)

#Button 3

tk.Radiobutton(root, text="Very Happy",fg="green",padx = 20,variable=v,value=3).grid(row=5, column = 2)

# Tick box

tk.Label(root,text="IF you requide for extra training please tick the box.", justify = tk.LEFT, padx = 20).grid(row=6, column = 0)
var1 = IntVar()
Checkbutton(root, text="APR", variable=var1).grid(row=7, column = 0)
var2 = IntVar()
Checkbutton(root, text="THS", variable=var2).grid(row=8, column = 0)
var3 = IntVar()
Checkbutton(root, text="GOODS IN", variable=var3).grid(row=9, column = 0)
var4 = IntVar()
Checkbutton(root, text="DESPATCH", variable=var4).grid(row=10, column = 0)
var5 = IntVar()
Checkbutton(root, text="LLOP", variable=var5).grid(row=11, column = 0)
var6 = IntVar()
Checkbutton(root, text="REACH TRUCK", variable=var6).grid(row=12, column = 0)
var7 = IntVar()
Checkbutton(root, text="CBT", variable=var7).grid(row=13, column = 0)



# Add comment

tk.Label(root, text="If you have any additional comments about your current position, manager ar any thing else please share with us.").grid(row=14, column= 0)
e3 = tk.Entry(root)
e3.grid(row=15, column=0)

#Submit button
def callback():
    print("Full name:",e1.get())
    print("Employy Number:",e2.get())
    print("APR",var1.get())
    print("THS", var2.get())
    print("GOODS IN ", var3.get())
    print("DESPATCH ", var4.get())
    print("LLOP ", var5.get())
    print("REACH TRUCK ", var6.get())
    print("CBT ", var7.get())
    print("Addition comment:",e3.get())
#Sending an e-mail

people = ['my e-mail'] for i in people: o = win32com.client.Dispatch("Outlook.Application")

Msg = o.CreateItem(0)
Msg.Importance = 0
Msg.Subject = 'Subject'
Msg.HTMLBody = ("")


Msg.To = i

Msg.SentOnBehalfOfName = "sender"
Msg.ReadReceiptRequested = True



Msg.Send()
MyButton1 = Button(root, text="Submit", width=10, command=callback)
MyButton1.grid(row=16, column=0)

#Sending an e-mail

people = ['my e-mail']
for i in people: 
    o = win32com.client.Dispatch("Outlook.Application")

    Msg = o.CreateItem(0)
    Msg.Importance = 0
    Msg.Subject = 'Subject'
    Msg.HTMLBody = ("")


    Msg.To = i

    Msg.SentOnBehalfOfName = "sender"
    Msg.ReadReceiptRequested = True



    Msg.Send()


root.mainloop()
Damian
  • 1
  • 1
  • ***" how to get #Button1, 2 and 3"***: You can't, as you didn't assign it to a reference variable. First you have to understand [Event-driven programming](https://stackoverflow.com/a/9343402/7414759). Read also [AttributeError: NoneType object has no attribute ...](https://stackoverflow.com/a/1101765/7414759) – stovfl Mar 07 '20 at 15:21
  • ok,thanks for help with that I try to use it. But i ma still struggle how to get all data from 'def callback():' and paste it to 'Msg.HTMLBody' – Damian Mar 07 '20 at 15:37
  • 1
    Put the whole ***#Sending an e-mail*** part into a function and call it after `def callback(...` has prepared the data. This likely leads to [Freezing during the execution of a function](https://stackoverflow.com/questions/10847626/program-freezing-during-the-execution-of-a-function-in-tkinter) – stovfl Mar 07 '20 at 15:42
  • `mainloop()` starts tkinter's program - it shows tkinter's window. So you send mails before you even see tkitner's window. You have to send mails inside function `callback()` – furas Mar 07 '20 at 15:49
  • I tried but still come up with some errors on the screen (maby i doing something wrong) but thanks for your help. – Damian Mar 07 '20 at 15:54
  • @Damian ***"I tried but still come up with some errors"***: [Edit] your question and show your attempt and the Traceback. – stovfl Mar 07 '20 at 17:10
  • @Damian You have duplicated the ***whole `#Sending an e-mail part`*** part, which is still outside of function `def callback(...`. This makes no sense? – stovfl Mar 07 '20 at 20:45
  • That's why I just applied here because I'm just started with python/tkinter and I try to understand how it works, even if some of the things make no sens to me as well but thanks your help its make it a litle bit easy. – Damian Mar 07 '20 at 21:02

0 Answers0