I am new to python and I need python combobox selection to show on an excel sheet('Header'), range('C25'). The code I am using is as follows. Any help will be highly appreciated
What I have tried:
<pre><pre lang="Python">
import tkinter as tk
from tkinter import ttk
from tkinter.messagebox import showinfo
from calendar import month_name
import xlwings as xw
class ComboboxSelectionWindow():
def __init__(self, master):
self.master=master
self.master.geometry('500x250')
self.master.style= ttk.Style()
self.master.style.theme_use('clam')
self.master.style.configure("TCombobox", fieldbackground= "light blue", background= "white")
self.entry_contents=None
self.labelTop = tk.Label(master,text = "Porosity Scale Selection", background = 'blue', foreground ="white", font = ("Arial", 15))
self.labelTop.place(x = 20, y = 10, width=240, height=30)
self.comboBox_example = ttk.Combobox(master,values=["Limestone","Sandstone","Dolomite"])
self.comboBox_example.current(0)
self.comboBox_example.place(x = 20, y = 60, width=200, height=25)
self.okButton = tk.Button(master, text='OK',command = self.callback)
self.okButton.place(x = 20, y = 90, width=140, height=25)
def callback(self):
""" get the contents of the Entry and exit
"""
self.comboBox_example_contents=self.comboBox_example.get()
self.master.destroy()
def ComboboxSelection():
app = tk.Tk()
app.geometry('180x100')
Selection=ComboboxSelectionWindow(app)
app.mainloop()
return Selection.comboBox_example_contents
wb = xw.books['1. Petrophysical Analysis.xlsx']
shth = wb.sheets['Header']
wb.sheets['Header'].select()
wb.sheets['Header'].cells(25, 3).Value = ComboboxSelection()